Get_Result() Doesn't Work Even MySQLnd Is Enabled

get_result() Doesn't Work even mysqlnd is enabled

To make this thing work, Enable nd_mysqli in php extensions and disable mysqli. This will work like charm!

mySQLi prepared statement unable to get_result()

Through some checking, even though mysqli is installed on my host, apparently the mysqlnd driver is not present. Therefore, get_result() can not be used(php manual defines get_result as mysqlnd dependent), and instead extra coding would need to be done to handle my result the way I would like.

Therefore, I decided to try and learn how PDO works, and within minutes, voila!!!

Replaced the above code with this:

function checkUsernameEmailAvailability($username, $email) {

echo 'pdo about to be created';

$dsn = 'mysql:dbname='.C_BASE.';host='.C_HOST;
$user = C_USER;
$password = C_PASS;

try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

$params = array(':username' => $username, ':email' => $email);

try{
$sth = $dbh->prepare('SELECT username,email FROM tb_users WHERE username = :username OR email = :email ');
} catch(PDOException $e) {
echo 'Prepare failed: ' . $e->getMessage();
}

try{
$sth->execute($params);
} catch(PDOException $e) {
echo 'Execute failed: ' . $e->getMessage();
}
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);
}

As much error checking as I could think of, and no problems at all first crack at it!

Final Code

function checkUsernameEmailAvailability($username, $email) {
$dsn = 'mysql:dbname='.C_BASE.';host='.C_HOST;
$user = C_USER;
$password = C_PASS;
new PDO($dsn, $user, $password);

$params = array(':username' => $username, ':email' => $email);

$sth = $dbh->prepare('SELECT username,email FROM tb_users WHERE username = :username OR email = :email ');
$sth->execute($params);
$result = $sth->fetch(PDO::FETCH_ASSOC);

print_r($result);
}

Query method doesn't work - missing mysqlnd driver

A quite similar approach using call_user_func_array()
You can find some solutions in the Comments section on the manual page

I have no idea why mysqli require all this unnecessary toilsome stuff while PDO does it out of the box. Compare your soon-will-be code with this one:

function query($query, $params=NULL) {
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
}

Is possible to enable MySQL Native Driver (mysqlnd)?

mysqldnd is a library that provides MySQL-connectivity to mysql_*, mysqli_* and PDO functions/methods.

Those three extensions are compiled either with mysqlnd, or with libmysql ; and cannot be compiled using both at the same time : they use one library, or the other.

This means the only way to switch between libmysql and mysqlnd is to re-compile PHP (or, at least, the mysqli extension, in your case) ; or to install a version of it that is compiled against the library you want.

Basically, this can only be done by the administrator of your server -- so, in your case, you seem to be stuck with libmysql ; even if it lacks some interesting features.


Once again, using an hosting service with which you are not administrator has advantages (less maintenance for you, you probably pay less), but you are not able to do whatever you want with "your" server.



Related Topics



Leave a reply



Submit