I am building an application which includes prepared mysqli statements.
I use Object oriented PHP.
The day before yesterday everything was working great.
Yesterday I updated my Ubuntu machine (which I currently use as web server).
Today I was trying again and poof! there was an error.
"call to undefined method mysqli_stmt::get_result()"
So I went to the internet and found out that get_result needs the mysqlnd library.
So I used the following to check if the library is included:
if (extension_loaded('mysqlnd')) {
echo 'extension mysqlnd is loaded'; //works
}else{
echo 'extension is not loading';
}
And indeed I got the message that the extension is not loading. What I want to do now is try to load the library, but how do I do that?
The best I could found was this:
http://php.net/manual/en/mysqlnd.install.php
But even with some trial and error I can't get this to work.
Question: How do I load the mysqlnd library?
You cannot load mysqlnd library. This is a special PHP extension that cannot be enabled/disabled by PHP ini config and the extension doesn't expose any functionality by itself.
Mysqlnd is a client library for connecting to MySQL servers. It's actually a C library implemented as a PHP extension. It means that you can use it when writing another PHP extension in C, e.g. mysqli, PDO_MySQL or php_mysql.
The only way it can be enabled/disabled is during the compilation of PHP source code via one of the compilation flags for either mysqli or PDO_MySQL extensions. You need to recompile your PHP distributable with the appropriate flag (the flag is set to On by default, so if you are missing some functions in mysqli it means your PHP was compiled with libmysql instead).
Related
I am starting a new project in PHP that need to access MS Sql Server.
I know that PHP's manual lacks of warns about old or even deprecated set of functions.
MySQL extension do not refer to MySQLi extension at any point.
SQLite extension do not refer to SQLite3 extension at any point.
So my question is: Am I OK using PHP's SQLSRV Functions? or they are not the state of the art? I did choose them because aparently they have MS support.
Please notice that I am not asking for a recomendation, just if what I choose is OK
As I understand it the SQLSRV functions aren't actually PHP's per se since they are part of a package maintained by Microsoft outside the main PHP project. They are however one of the two best bets for working with MS SQL Server (PDO_SQLSRV being the other) since they are currently maintained.
They are both currently Windows only.
We have developed a web-application that runs on various server environments (> PHP 5.3), which currently uses the "deprecated" mysql extension to connect to mysql. Since PHP 7 however, it seems mysql is not installed by default, only the newer mysqli extension.
So we would like to convert our scripts to use mysqli, but we are concerned if the mysqli extension is not installed on "older" servers. So the question basically goes: Is mysqli generally ubiquitous since PHP version 5.3? Does anyone know from what version of PHP mysqli comes installed as default?
If some of our users are on hosts without mysqli, we would need to create a wrapper script, that detects if mysqli is available, and fall back to mysql if not.
Anyone with knowledge care to shine some light on this? Thanks
MySQLi was added with PHP 5.0
You can check if mysqli is installed by doing this:
if ( function_exists('mysqli_connect') )
// mysqli is installed
I have installed Apache2.2 and then installed PHP5.4.8. I cannot get my new .php file to load in a browser because it keeps giving me the error Fatal error: Call to undefined function mysql_connect(). When I load the test.php file which has only this in it:
<?php phpinfo(); ?> it returns a page that shows information about PHP but where it would show the MySQL modules it only shows mysqlnd. What is that? Also, I have gone through the php.ini file and uncommented the proper lines for MySQL integration as well as having edited the Apache2.2 httpd file. Does anyone have any answers as to why MySQL isn't working? Thanks in advance.
Also, Ive tried many of the solutions from this website as well as many google searches. I can't seem to figure it out. :-(
1) Have a look on choosing MySQL API. It is recommended to use mysqli extension.
2) According to Other changes to extensions, the MySQL extensions mysql, mysqli and PDO_mysql use mysqlnd as the default library now.
A quote from MySQL Native Driver - mysqlnd site:
Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, mysqli and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API.
That means, the mysqlnd extension does not export any function you can use in your scripts, but acts as a bridge between your code and one of mysql, mysqli, pdo_mysql extensions.
You mentioned, that phpinfo() shows only mysqlnd. The fact you don't see section titled MySQL there means that mysql extension is not enabled (commented out) in php.ini (Windows) or your php is not compiled with mysql support (Linux). More details about installing MySQL extension are here.
What is your OS?
To have a successfull MySQL connection you should:
Install the MySQL Server
Configure the PHP to use the proper mysql socket: (in php.ini search for mysql.default_socket - point it to the mysql server).
Reboot the web server - Apache
I am currently trying to connect to my localdb on MSSQL 2012 Express.
I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098
I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could understand since it is not mentioned on the phpinfo() PDO section, but it has its own section + the get_loaded_extensions also shows sqlsrv. I suppose thats from the official MS Driver ? I am using the php_sqlsrv_53_nts.dll
With my Zend Server CE 5.6 with PHP 5.3.9
Now as far as I understood I downloaded the wrong driver and should try the one that is brought by the PECL manager? There is only the sourcecode available and obviously I am on a windows machine so I can forget about everything that I need to compile myself - I am actually getting the suffix errors when using the powershell and my pecl / pear installation.
Has anybody solve that problem ? Any help much appreciated
All the best,
Richard
The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
extension=php_pdo_mssql.dll
in your php.ini.
Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course).
//edit: just read you latest comment. This extension is available for a very long time now and can be considered working. If you are not allowed to use it you must rewrite your code to use the functions the native driver offers for PHP.
Another possibility is to use the odbc drivers which are by default included in the php extensions, you still might have to uncomment them in your php.ini though.
extension=php_pdo_odbc.dll
Don't forget to restart your server afterwards ;-)
And then use it like this:
$db = new PDO('odbc:Driver={SQL Server};Server=192.168.x.x;Database=DatabaseName; Uid=User;Pwd=Password');
$stmt = $db->query("SELECT the_usual FROM aTable WHERE all='well'");
Alright. I suppose its just one of these days.
I got the wrong extension loaded from the supplied ones by MS. I needed to use php_pdo_sqlsrv_53_nts
rather than
php_sqlsrv_53_nts
Thanks for all the help
I am trying to use the new development server in PHP 5.4. It runs phpinfo() just fine but on my site code and also phpMyAdmin.php they are throwing the following error:
Call to undefined function mysql_connect()
They are running through localhost:8000
php -m is showing that mysqlnd is loaded but that maybe not enough.
The OS is Windows 7
Any thoughts?
mysqlnd is the library that can be used since PHP 5.3, instead of libmysql, by 3 PHP extensions :
mysql, which provides the mysql_* functions,
mysqli, which provides the mysqli_* functons,
and pdo_mysql, which allows one to use PDO with a MySQL database.
mysqlnd by itself doesn't export any function you can use from your PHP scripts : it only provides MySQL connectivity to those 3 extensions -- which are the ones that export functions you can use.
If you want to use the mysql_* functions, you have to make sure that the mysql extension is enabled, with something that whould look like this in one of the .ini files parsed by PHP :
extension=mysql.dll
As a sidenote : the mysql_* functions should not be used anymore, especially for new projects : the mysql extension is old, and doesn't allow one to use recent (well, not that recent anymore, actually) features of MySQL.
Instead, you should be using mysqli or PDO.
It's because register_globals is no longer included as of PHP5.4, in earlier versions it was deprecated and you could force it on. The reason is because it would leave huge security gaps for hackers to exploit.
try install missing mysql module
sudo apt install php-mysqli
check if extension=mysql.so is set in php.ini after installation