mysql_connect() error message - php

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

Related

What's the difference between php_pdo_pgsql and php_pgsql PHP extensions?

My default php.ini file lists both extensions (installed via brew), and I sometimes see different variations on Linux (AMZN vs Centos) with the _pdo_ bit. What is the difference?
Update: I was getting errors saying pg_connect not found and this seems to be part of the non-PDO version. To get this installed on Mac via brew, I needed to add support by running brew reinstall php56 --with-postgresql
PDO is short for PHP Data Objects and is an abstraction that can be mapped on to a lot of different databases. This means you can move between things like MySQL, PGSQL and SQLite very easily. The PDO module enables the functions you see here for PGSQL.
The non-PDO module is specific to Postgres and will enable this set of non-standardized functions that will only work with Postgres databases.
The PDO extension can connect to different database management systems with the same syntax, as long as there's a driver for the system you want to use. The PostgreSQL extension can only connecto to PostgreSQL.
What you see is the PostgreSQL extension and the PDO driver for PostgreSQL.

can't enable PDO in localhost apache php vesion 5.2.6

I can't enable PDO in my localhost.
I have read the php installation manual and attempted to do the same thing, but it isn't working.
When i open phpinfo and search for pdo it appear that pdo_mysql is not enabled, as shown in the below image.
I uncommented all pdo extension in php.ini and that didn't help.
I also searched for the pdo.dll in my extension and found it.
Any ideas what is wrong?
From the image of your phpinfo it's only showing sqllite and mysql is missing.
In PHP 5.2 I believe PDO is not available under default compile so you'll need to make sure it's actually compiled into PHP by adding --with-pdo-mysql into your compile script or if available via your webhosting panel somewhere. Personally I'd recommend having your PHP version updated to a secure version but as always you have to make sure any existing code is compatible.

Can phpmyadmin use pdo_mysql to access mysql?

My php installed with pdo_mysql, without mysqli/mysql. When I use phpMyAdmin, it showed
"The mysqli|mysql extension is missing".
I tried many times to install mysqli/mysql but failed, and I don't want to re-compile php. So I gave up and chose another mysql web tool Adminer which can use pdo_mysql.
Question : Is it possible that phpMyAdmin use pdo_mysql to access mysql db? I think it should be not hard ,since another tool can.
This information is not immediately available in the online documentation, but the FAQ has it:
phpMyAdmin can connect to your MySQL server using PHP’s classic MySQL extension as well as the improved MySQL extension (MySQLi)
The phrasing is more explicit in their Wiki:
[Requirements]
(...)
Either the mysql or mysqli extensions
(...)
So the answer is: not by default, but contributions are welcome :)

Working with MS SQL SERVER on PHP5.6

So I have a trouble here. Tried use mssql_connect() but interpeter says that function is undefinied. PHP.net advices this, but it suppports only older versions of PHP. Is it possible to connect to MS SQL Server database from PHP5.6? What extensions should I add, what functions can I use?
Configuration details: localhost, Apache 2.4, PHP 5.6, OS Windows 8.
You need to enable the MSSQL extension in the PHP.ini file.
If this extension is not installed, you need to install it in PHP.
Please tell your server details (OS/WebServer like apache nginx) so that I can explain in detail.
Use
<?php phpinfo();?>
to see what are available with your php installation. I advice you to use PDO instead of mysql_* functions. It supports several databases not only MSSQL or MySQL.

PDO MSSQL Server - Driver not found

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

Categories