quoteInto() and Zend_DB generate error - zend-db

I have written a piece of code to see if the record is already in the db, the code is like this :
$sql = $dbRead->quoteInto('SELECT email FROM betaEmail WHERE validate = ?'.$_POST['validate']);
and for connection, I am using Zend_Db_Adapter_Pdo_Mysql . The following error is generated, what should I make out of it? Any solution?
Warning: Missing argument 2 for Zend_Db_Adapter_Abstract::quoteInto(), called in
/Applications/MAMP/htdocs/myform/user_registration.php on line 16 and defined in
/Users/payam/php_library/ZendFramework-1.11.8/library/Zend/Db/Adapter/Abstract.php
on line 927

Change your . to a ,:
$sql = $dbRead->quoteInto('SELECT email FROM betaEmail WHERE validate = ?', $_POST['validate']);

Related

ERROR com.intuit.karate.core.FeatureParser - syntax error: mismatched input '<EOF>' expecting {FEATURE_TAGS, FEATURE} [duplicate]

As I'm trying to automate the API testing process, have to pass the XML file to Read method for example,
Given request read ( varXmlFile )
FYI: XML file is present in the same folder where the feature file exists.
Doing this, its throwing an exception like this
com.intuit.karate.exception.KarateException: called: D:\workspace\APIAutomationDemo\target\test-classes\com\org\features\rci_api_testing.feature, scenario: Get Membership Details, line: 15
javascript evaluation failed: read (varXmlFile )
So Karate doesn't allow this way or can we have any other alternative ?
Suggestion please.
Thanks
Please ensure the variable is set:
* def varXmlFile = 'some-xml-file.xml'
Given request read(varXmlFile)
Or just use normally:
Given request read('some-xml-file.xml')
The problem got solved as in the variable varXmlFile holds the file name along with single quote like this 'SampleXmlRequest.xml'.
So I removed the single quote while returning from the method.

Is pass by reference supported in php 7?

Recently we migrated PHP 5.6 to PHP 7
and now following code throws $this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
any ideas? what are the alternation that I could use for it?
As per the PHP7 incompatible changes: http://php.net/manual/en/migration70.incompatible.php
New objects cannot be assigned by reference
The result of the new statement can no longer be assigned to a
variable by reference: <?php class C {} $c =& new C; ?>
Output of the above example in PHP 5:
Deprecated: Assigning the return value of new by reference is
deprecated in /tmp/test.php on line 3
Output of the above example in PHP 7:
Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php
on line 3
There is no alternative. You were using deprecated behavior, and now it's no longer valid PHP. Simply don't assign by reference.
To clarify Marc B's answer: just remove the ampersand like this
$this->a = new test($this->f);
You can do this as alternative:
$test = new test($this->f);
$this->a = $test;
now the $test is passed by reference and if you change attributes of $this->a, $test attributes will also change. and conversely.
PHP 7 is "pass by reference" by default. if you don't want to pass an object by it's reference, you should do this:
$a = clone $b;

Why my sql comment parsing EReg expression not compile?

I have an sql querying tool that is written in Haxe and im trying to add some sql comment support to the code. Currently if a user has any comments (single line or multi line) the query fails on the server side. Thus, im trying to write a simple method that takes the sql the user inputs and replaces any comments with a "". Here is method
static function removeComments(snippet: SqlSnippet): SqlSnippet {
var rComment: EReg = ~/(--[^\n]*)|(/\*[\w\W]*?(?=\*/)\*/)/;
var resultSql = rComment.replace(snippet.sql, "");
snippet.sql = resultSql;
return snippet;
}
My issue isnt with this method, but that neko wont compile it. When i try to compile this method i get this message:
src/skyview/SqlSnippetParser.hx:30: character 33 : Invalid character '\'
[Finished in 0.2s with exit code 1]
the '\' this message is refering to is the '\' im trying to use to escape the '*' metacharacter at the beginning of the 2nd set of "()"
Does anyone know why nako wont compile the "/*" in this EReg?
The problem is not \*. It is / needs to be escaped.
Try changing your EReg to ~/(--[^\n]*)|(\/\*[\w\W]*?(?=\*\/)\*\/)/.

Share sqlite2 database with Yii webapp

Hi I've got a sqlite2 database that is being used by a PHP webapp and I want a Yii webapp to access it. At the moment I copied the db file to a local server and I've changed config/main.php to:
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/thedatabase.db',
),
When I run the Gii model generator I get:
CDbException
CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database. The SQL statement executed was: SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'
BTW I am able to convert the database to SQL using
Exporting sqlite2 database to SQL
Though I want the database to stay as an sqlite2 database so that the Yii app can access up to date user info.
After some thought it looks like it would be simpler to just use some code from the old PHP project in the Yii project...
$db = sqlite_open($databasefilename, 0666, $sqliteerror);
$query = sqlite_query($db, "SELECT password FROM user WHERE username='$username'");
$row = sqlite_fetch_array($query);
if ($row) {
return $row[password];
}
Edit:
When using that code I get the following error:
undefined function sqlite_open()
I'm using PHP Version 5.4.7...
http://au1.php.net/manual/en/function.sqlite-open.php
Here it says:
PHP 5 < 5.4.0
I got it working with the sqlite2 database by using 'sqlite2:' instead of 'sqlite:'
'db2'=>array(
'class'=>'CDbConnection',
'connectionString' => 'sqlite2:'.dirname(__FILE__).'/../../../thedatabase.db',
),
I can do queries like this:
Yii::app()->db2->createCommand($sql)->queryAll());
To stop Error 500 Object configuration must be an array containing a "class" element 'class'=>'CDbConnection' is required in config/main.php. I think that info is already included in the first database connection somewhere.

PHP error_log errors to MySQL

In a previous ticket i asked about logging PHP errors in MySQL which gives me:
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
// mysql connect etc here...
$sql = "INSERT INTO `error_log` SET
`number` = ".mysql_real_escape_string($errno).",
`string` = ".mysql_real_escape_string($errstr).",
`file` = ".mysql_real_escape_string($errfile).",
`line` = ".mysql_real_escape_string($errline);
mysql_query($sql);
// Don't execute PHP internal error handler
return true;
}
// set to the user defined error handler
$new_error_handler = set_error_handler("myErrorHandler");
I can make this work but only if it is triggerred like this:
trigger_error("message here");
However, I also want the error handler to be called for all errors such as syntax errors like:
echo "foo;
But these errors are just outputted to the screen, what am i doing wrong?
You can only handle runtime errors with a custom error handler. The echo "foo error in your example happens when parsing (i.e. reading in) the source. Since PHP can not fully parse the code, it can also not run your error handler on this error.
If You're forced to test if syntax is correct, You can use php_check_syntax function, with filename parameter PHP Manual php_check_syntax
php_check_syntax also provides second parameter, witch when used will be populated by the error string, as far as i remember
That's indeed terrible way of error logging
You don't need not a single advantage of a database. Would you make a database lookup for the certain line number? Or order your results by file name?
database is a subject of many errors itself.
You've been told already that it's impossible to catch a parse error at the program logic level, because a syntactically wrong program will never run.
Let's take your code as an example. It will raise a MySQL error (because of poorly formed query) which you will never see. As well as any other errors occurred. That's what I am talking about.