Mysqli statement parameter not found running PHPunit test under Eclipse - php

I run PHPunit tests via Apache, ou directly in Eclipse (ZendStudio in fact). All run well via Apache, but under Eclipse i have this error :
zend mysqli statement execute error no
data supplied parameters prepared
statement
The php version is the same (5.2.10), ZendFramework is 1.9 and here is the code
function isValidProject($sName)
{
$db = Zend_Db_Table::getDefaultAdapter();
$req = $db->prepare('SELECT id_project FROM sys_projects WHERE url_alias=?');
$req->bindParam(1, $sName);
$req->execute();
$row = $req->fetch();
if($row) return $row['id_project'];
else return FALSE;
}
I have tried with this way too, with the same result
$req = $db->query('SELECT id_project FROM sys_projects WHERE url_alias=?', array($sName));
Thanks
Cédric

I've similar errors, where one of the places I was running the code did not have the same module configuration as the other - in that case, mysqli was not installed/available on the server that reported the failure.
examining the output of phpinfo(), run through Apache vs Eclipse should provide some enlightenment.

Related

Thrift + Cassandra + PHP + Windows?

Connecting to Cassandra with PHP is really a pain. The documentations at Apache and DataStax are extremely poorly written - for Windows users.
I have Thrift installed (I believe!) via Chocolatey. But I am still not able to compile php code for Cassandra using thrift.
If you look at this link ,
now we can compile php code for Cassandra using thrift I used command: d:\cassandra\trift\thrift.exe --gen php
d:\cassandra\interface\cassandra.thrift
So what is cassandra.thrift and where does it come from?? WHAT should I put inside it??
If I follow the instruction exactly, I get this error,
Could not open input file: d:\cassandra\interface\cassandra.thrift
So what is going on?
How do I make this work?
I have tried to install DataStax PHP Driver for Apache Cassandra and that documentation even worst.
Why PHP modules do not come with Cassandra like it does for MongoDB? Most of the independent drivers I found are outdated, not supported anymore or abandoned.
EDIT:
From the README,
Install the PHP extension
Installing with pecl
The PHP driver is not published to the official PECL repository yes.
You can still install it using pecl by specifying the provided
package.xml file path as the argument to pecl install command.
Install the 2.0 version of the C/C++ driver
not published to the official PECL repository yes - is it yes or yet?
Obtaining Build Dependencies
CMake
Git
ActiveState Perl
Python v2.7.x
I have downloaded and installed. Then, what? In Building the Driver,
A batch script has been created to detect installed versions of Visual...
What? Where does A batch script suddenly come from??
Then,
First you will need to open a “Command Prompt” (or Windows SDK Command
Prompt) to execute the batch script.
Usage: VC_BUILD.BAT [OPTION...]
--DEBUG Enable debug build
--RELEASE Enable release build (default)
--DISABLE-CLEAN Disable clean build
....
What are these bunch of '--' for?
To build 32-bit shared library:
VC_BUILD.BAT --X86 To build 64-bit shared library:
VC_BUILD.BAT --X64
Where does .BAT come from? What should I put inside it? Where should I run it from??
After all, what are those Build Dependencies for? How do I use them??
Just hope that someone can write a proper guide then the guide above - it is frightening! (if you compare the guides in MongoDB, it is far better and professional)
EDIT 2:
First error when I run the .bat from my desktop,
I have git installed already but I still have this error,
After fixing git issue above, I have a new one - it just frozen there, nothing happens,
The IDL file cassandra.thrift is usually part of the cassandra package, but you can find it following the link above. The link points to trunk, you may want another version.
After you downloaded the right version of that file or better found it in your downloaded Cassandra package in the interface folder, generate the code as outlined in the documentation you have. The rest should be easy.
Why PHP modules do not come with Cassandra like it does for MongoDB? Most of the independent drivers I found are outdated, not supported anymore or abandoned.
I'm not really sure about that, but my guess is that the fact CQL is promoted heavily for a while now instead of using the raw Thrift API - the latter is a complex task, while CQL is more easy to use - is one of the key factors why it is this way. It more or less eliminates the need for another wrapper.
PS: Just to be sure:
thrift.exe --gen php d:\cassandra\interface\cassandra.thrift
could not open input file cassandra.thrift
Of course you point to the right drives, folders and files, do you?
Forget about Thrift and the 'beta', I found a better solution. It very straight forward and extremely easy!
Example codes,
require_once 'lib/Cassandra/Cassandra.php';
$cassandra = new Cassandra();
$s_server_host = '127.0.0.1'; // Localhost
$i_server_port = 9042;
$s_server_username = 'admin'; // We don't use username
$s_server_password = 'password'; // We don't use password
$s_server_keyspace = 'demo'; // We don't have created it yet
$cassandra->connect($s_server_host, $s_server_username, $s_server_password, $s_server_keyspace, $i_server_port);
// Tests if the connection was successful:
if ($cassandra) {
// Select:
// Queries a table.
$cql = "SELECT * FROM users;";
// Launch the query.
$results = $cassandra->query($cql);
// Update:
// Prepares a statement.
$stmt = $cassandra->prepare('UPDATE users SET first_name = ?, last_name = ? where id = ?');
// Executes a prepared statement.
$values = array('first_name' => 'Fred', 'last_name' => 'Smith', 'id' => '1');
$result = $cassandra->execute($stmt, $values);
// Insert:
// Prepares a statement.
$stmt = $cassandra->prepare('INSERT INTO users (id, first_name, last_name)
VALUES (:id, :first_name, :last_name)');
// Executes a prepared statement.
$values = array('first_name' => 'John', 'last_name' => 'Robinson', 'id' => '4');
$result = $cassandra->execute($stmt, $values);
// Delete:
// Prepares a statement.
$stmt = $cassandra->prepare('DELETE FROM users WHERE id = :id');
// Executes a prepared statement.
$values = array('id' => '4');
$result = $cassandra->execute($stmt, $values);
// Closes the connection.
$cassandra->close();
}
Update:
The datastax PHP driver is now GA and binaries are available for download (no need to build it yourself):
https://github.com/datastax/php-driver
Regarding the DataStax PHP driver, the instructions are being improved per your feedback as I type.
Because this Driver is in Beta, we do not yet have pre compiled binaries that you can simply download. They will be available once the driver is GA. For now you will have to build them yourself.
The process for building the binaries is very straight forward. 1) Install the dependencies 2) run vc_build.bat.
You can find the vc_build.bat here (just right click save as from your browser):
https://raw.githubusercontent.com/datastax/php-driver/master/ext/vc_build.bat

php loop through results without using the native driver

I need to rewrite my php code so that it does not use the native driver php5-mysqlnd.
On my development machine my code works fine because I have php5-mysqlnd installed, but as soon as I installed php5-mysqlnd on my VPS host then apache failed and wouldn't start. And so I needed to have everything wiped and a fresh server install. It's something to do with Plesk, I don't care about those details I know I can't use php5-mysqlnd so I just need my php to work without it.
So I don't care that everyone says it is the wrong technology and I don't care if people say it's an old technology.
The code below works on my development machine and I need to rewrite it without the native driver, how do I do that?
$db = new mysqli($_SESSION["DB_HOST"], $_SESSION["DB_USERNAME"], $_SESSION["DB_PASSWORD"], $_SESSION["DB_DATABASE_NAME"]) or die('Cannot connect');
$stmt = $db->prepare("call get_languages( ? )");
$stmt->bind_param('i', $iLanguageId );
$stmt->execute();
if ($result = $stmt->get_result()) {
while ($row = $result->fetch_assoc())
{ echo "<p>" . $row['language'] . "</p>"; }
$result->free_result();
}
else
{ echo '<h2>Error: No languages listed.</h2>'; }
You could uninstall php5-mysqlnd switch back to libmysqlclient if that's what you want.
Another option is to use the PDO driver and rewrite your code to use PDO instead.

Using MSSQL with PHP on CentOS

I have installed and configured FreeTDS on my CentOS environment to enable my PHP code to get connect to some external MSSQL server. I have my entire application running on written using PDO which is running perfectly on windows. Just wanted to know if my same PDO code can be used even in CentOS or else I have to convert entire code from PDO to mssql_query form.
Like in PDO I have :
$statement_keyword = $obj->conn->prepare($keywordquery);
$statement_keyword->execute();
$rows_keyword = $statement_keyword->fetchAll(PDO::FETCH_ASSOC);
In MSSQL using FreeTDS we have to write
$result = mssql_query($keywordquery);
while ($Row = mssql_fetch_assoc($result)) {
$iw[$i++]=(string)$Row['FullName'];
.......
}
Means I have to run thru entire loop to get the record array, similarly there may be more changes that I need to make like in stored procedures execution ...
Can anyone guide me in using PDO for MSSQL on CentOS, or an easy way other round.
Thanks
After looking for net and doing some research and experimental work I realised it is very easy to use the PDO code for windows to PDO equivalent without must changes, the only change I need to make was in the manner the connection is establised
Using PDO with MSSQL In windows
$this->conn = new PDO("sqlsrv:server=".$this->dbServer.";Database={$this->dbName}",$this->userName,$this->userPassword);
Using PDO with MSSQL on CentOS
$this->conn = new PDO("dblib:host=$this->dbServer;dbname={$this->dbName}",$this->userName,$this->userPassword);
Make sure you have configured FreeTDS, ODBC , etc on your CentOS Stack

PDO bind parameter fails silently on staging and hosting server

I am using WindowsXP machine for the PHP pages I am developing. I am using PDO to connect to MySQL backend. In my development environment it works just fine but it silently stops processing in my CentOS 5.5 testing server. After some debugging, I found that it stops exactly at '$stmt->bindParams' section.
My statement is as follows:
$stmt = $dbh->prepare('SELECT * FROM MEMBERS WHERE ID=:what');
echo 'statement prepared'; //debug
$stmt->bindParam('what', $enteredid);
echo 'parameters bound'; //debug
also tried
$stmt->bindParam('what', $enteredid, PDO::PARAM_STR, 255);
both works in my development machine but it stops in my test server.
I can only see 'statement prepared' and nothing happens.
Also tried the page in hosting environment. Same thing happens.
When you call bindParam() don't you need to pass ':what' as the placeholder to bind to instead of 'what'? Not sure why this would work on Windows and not Linux though...
Old, but someone might find this useful
The correct code is:
$stmt = $dbh->prepare('SELECT * FROM MEMBERS WHERE ID=:what');
echo 'statement prepared'; //debug
$stmt->bindValue(':what', $enteredid);
echo 'parameters bound'; //debug
$stmt->execute();

What does Apache need to support both mysqli and PDO?

I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover.
My problem is this: so far, either one or the other method will crash Apache.
Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this:
$dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
echo 'Connected to database';
$sql = "SELECT * FROM `employee`";
But this line makes Apache crash:
$dbc->query($sql);
I don't want to redo my entire Apache or XAMPP installation, but I'd like for PDO to work. So I tried updating libmysql.dll from here, as oddvibes recommended here. That made my simple PDO query work, but then mysqli queries crashed Apache.
(I also tried the suggestion after that one, to update php_pdo_mysql.dll and php_pdo.dll, to no effect.)
Test Case
I created this test script to compare PDO vs mysqli. With the old copy of libmysql.dll, it crashes if $use_pdo is true and doesn't if it's false. With the new copy of libmysql.dll, it's the opposite.
if ($use_pdo){
$dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
echo 'Connected to database<br />';
$sql = "SELECT * FROM `employee`";
$dbc->query($sql);
foreach ($dbc->query($sql) as $row){
echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
}
}
else {
$dbc = #mysqli_connect($hostname, $username, $password, $dbname) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
$sql = "SELECT * FROM `employee`";
$result = #mysqli_query($dbc, $sql) or die(mysqli_error($dbc));
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
}
}
What does Apache need in order to support both methods of database query?
Not a direct answer, but perhaps it can help you in your search for it:
The legacy mysql extension (The function prefixed with mysql_) is a thin wrapper over libmysqlclient. The new mysqli extension is essentially the same, but it implements some functionality that were introduced in later versions of libmysqlclient. PDO also uses libmysqlclient, but doesn't map it as directly as the other extensions do. This all amounts to 3 different php-extensions that all refer to the same native library. If some of them make assumptions about the version of the library, it might cause them to clash.
I would suggest that you install the newest version of libmysqlclient.dll that you can find and try to disable the legacy mysql extension (if you haven't already).
If you have code that uses mysql extension, you can have mysqli bind to those functions and it should work the same.
Also, make sure that you don't have the new mysqlnd driver installed for some reason. mysqlnd is an alternative implementation of libmysqlclient and it really just makes everything even more complicated.
Yes, it's a big mess.
It seems like all you need is to uncomment the correct extension directives in php.ini, like extension=php_mysqli.dll and extension=php_pdo_mysql.dll.
I never confirmed this with XAMPP, because I got frustrated with it and decided to install Apache, PHP and MySQL individually. In the process, I learned to do the above steps, along with a lot of other things. So I haven't confirmed that this will work with XAMPP, but I don't see why not, unless it doesn't come with the right drivers.
The two drivers (.dll files) in the example directives above are the ones I'm using. I also set extension_dir = "c:/php/ext" in php.ini - you should make sure that path points to the directory where your php extensions are. (Note that one of the nice things about installing these components separately is that I can put PHP in c:\php instead of having it buried several levels deep in c:\xampp.)
If anybody wants to follow along with installing your server components separately, I documented the whole process, with screenshots, on my blog.
same as Why does this pdo::mysql code crash on windows?
but dont have the solution for the moment
Crash happens only on "SELECT * FROM xxx" query() and prepare/execute
The unique solution i found :
Install LibMySQL.DLL FROM 5.0.51a package (working with last 5.1.44 MySQL Version)
http://www.netfulvpc.fr/files/libmysql_dll.zip
Ok, i have a very bad but working solution :p)
Open ext\php_pdo_mysql.dll with an Hex Editor
Search for "83 C3 50" offset 0x000024d5 (in php 5.2.12 vc6)
Replace by 83 C3 "54"
The problem is a bad structure size... (struct pdo_column_data)
I tried to fix that in libmysql.dll but that crash php_mysqli ;)

Categories