Problem in connectivity with mysql in php - php

I am trying connectivity with mysql in php. But it shows an error message at this line.
$con = mysql_connect('localhost','root','admin');
fatal error: Call to undefined function mysql_connect()

My guess is that the MySQL Extension has not been enabled/installed:
http://www.php.net/manual/en/mysql.installation.php (the original mysql extension)
or
http://www.php.net/manual/en/mysqli.installation.php (the newer mysql extension)
P.s. I would recommend skipping those and using PDO :)

Are you sure you have MySQL installed ?

Related

select the MySQLi driver rather than the MySQL driver in OJS (Open Journal System)

I have this error:
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/epuedu/public_html/journal/epuojs/ojs/lib/pkp/lib/adodb/drivers/adodb-mysql.inc.php:456
After googleing this error on OJS: I found this answer:
If it is PHP 7 you may need to select the MySQLi driver rather than the MySQL driver.
So i understand that PHP7 don't use MYSQL driver any more.
My question: How can swithch OJS connetion to MYSQLi driver?
Thanks
I found that I can select the driver from the first page of installing OJS, after choosing User name, password, database details, you can chose MySqli as well.
I hope this answer help others like me.
Alternatively, if you have access to the config.inc.php go to the database section and update the driver to "mysqli", eg:
;;;;;;;;;;;;;;;;;;;;;
; Database Settings ;
;;;;;;;;;;;;;;;;;;;;;
[database]
driver = mysqli

SQL server for php whit USBWebserver

I have installed the lastest version of sql-server for php. I use a simple USBWebserver and I have pasted all the driver files to the map C:\php\ext (see image below). In the file php\php.ini, I have place this string behind:
extension=php_sqlsrv_56_ts.dll
Here can you see all the files in C:\php\ext for running the driver:
Whit this I have no errors (but maybe he didn't throw it).
Now my problem is when I make my connection to the sql server database. I have the following error:
Fatal error: Call to undefined function sqlsrv_connect() in c:\root\add.php on line 2
This is my code where I've the exception:
$conn = sqlsrv_connect( array("Database"=>"Immo"), ".\\SQLEXPRESS");
Can anyone help me?Thanks and sorry for my poor english.
The string that you must place in your php\php.ini file is this:
extension=php_sqlsrv_54_ts.dll
And for make a connection you must turn the two arguments from place.
$conn = sqlsrv_connect(".\\SQLEXPRESS", array("Database"=>"Immo"));
This has help me to make a connection to a SQL-server with php.

mysql_connect error

In the following code I see echo1 statement, after which I do not see anything printed on the UI.The username and password is correct. But PHP doesn't seem to connect to MySQL. Don't even see the die statement what am I doing wrong. After mysql_connect is encountered the rest of the code doesn't work:
<?php
echo "echo1==========";
$con = mysql_connect("localhost","root", "xxxx123") or die("Error connecting to database");
echo "+++++++++ echo2";
echo $con;
mysql_close($con);
?>
You should be mising an error. Add :
ini_set('display_errors', 1);
error_reporting(E_ALL);
at the beggining of your script
No output means a fatal error. The only possible fatal error is "undefined function mysql_connect (unless something's really messed up somewhere). This means the mysql library is not installed, or it might just not be enabled in the php.ini file.
Check said file, and while you're at it turn error_reporting on.
If you use your code just like this then it's vulnerable for SQL Injection. I would strongly recommend using mysql_real_escape_string as you insert data into your database to prevent SQL injections, as a quick solution or better use PDO or MySQLi.
If you are going to use mysql_* then I'd recommend reading the PHP manual chapter on the mysql_* functions,
where they point out, that this extension is not recommended for writing new code. Instead, they say, you should use either the MySQLi or PDO_MySQL extension.
I also checked mysql_connect and found a weird regularity which is - if you use " on mysql_connect arguments, then it fails to connect and in my case, when I was testing it, it happened just described way, so, please try this instead:
$con = mysql_connect('localhost','username','password');
Replace " to ' as it's shown in the PHP Manual examples and it might work!
EDITED
For those who downvote - TRY first! I tested it on my server with " and it gave me an error: Warning: mysql_connect(): Access denied for user. I use PHP version 5.4.6!
Login to your server with SSH and run php --modules - if you don't see mysql in the list - then it's the reason of your fatal error.
The issue was that the ph5-mysql driver was not installed .Installed it and got it working..Now mysql_connect() function works..Thanks for all the help
For Tomcat 7, the default dir for php.ini is actually C:\windows. So modified (enabling modules, extensions etc.) php.ini should be copied to C:\windows. Then run phpinfo();. It should work fine even on Tomcat 7 along side PHP 5.x. I had this problem and struggled a lot when I wanted the mysql statements to work.
Even after following all instructions from answers in [779246] (Run a php app using tomcat?), mysql statements didn't work (Tomcat 7, PHP 5.2.16, PECL 5.2.5, MySql 5.6 on Windows 7). So I started looking into "phpinfo();" output carefully and used solution as mentioned in earlier paragraph. Please be sure to enable mysql dll extension and also PDO extensions in php.ini if you would like to use PDO (which is future of plain mysql_* methods in PHP).

db2_connect to as400 with php and wamp server

I have been trying to connect to a ibm db2 database but it seems impposible. The as400 is in a different server than the one running php.
Everytime I do a db2_connect I get the following error:
Fatal error: Call to undefined function db2_connect()
How can I make this function work?
Tip: I've already tried with odbc and it was a lost of time, but I'm open to suggestions on that path as well.
[EDIT]
I finally changed to java... it was impossible with php...
Check your php.ini file and make sure it has the DB2 extension enabled. http://www.php.net/manual/en/install.pecl.php
Try this link:
http://www.theregister.co.uk/2006/08/09/db2_udb_part2/
Deals with:
Installing the PHP DB2 extension,
Creating a connection,
Obtaining a result set
Also gives as an alternative the PDO option.
But as for DB2 on the AS400, am not sure if something still needs to be installed on the
AS400 for this to work?
Anyway, have used the ODBC Client Access with no problems at all. What difficulty did you run into?

Using SQL Server in Cake PHP: PHP SQL Server interface is not installed

I inherited an old Cakephp site that was using adodb as a driver to connect to an MSSQL database and it turns out this is no longer supported in the new version of cake (1.3, we are in 1.2) so I'm trying to change the driver so I can upgrade. We're using IIS and a sql server 2005 database on a different server, php 5.2.17. However using driver "mssql" gives me the following errors:
PHP SQL Server interface is not installed. For troubleshooting information, see http://php.net/mssql/
Call to undefined function mssql_min_message_severity()
The top error leads me to a page regarding the old php_mssql.dll, which according to this question: ( CakePHP: error when trying to use mssql datasource ) will become a problem when I switch to PHP 5.3 so I'm trying to use the php_sqlsrv*.dll for my php version but I still get the error. Could never get the mssql.dll one to work either. I do however see "sqlsrv support enable" in phpinfo.php and the whole sqlsrv section is intact there.
In cake php I'm using "driver => 'mssql'", is this the correct driver for the new sqlsrv dll? Is there something I'm missing? For kicks I tried 'driver' => 'sqlsrv', that fixes the php SQL Server interface error but I still get
"Fatal error: Call to undefined function sqlsrv_min_message_severity() in C:\Inetpub\wwwroot\riverstone-dev\www\cake\libs\model\datasources\dbo\dbo_sqlsrv.php on line 107"
Installing the latest SQL Native Client set from Microsoft and reenabling the extension in PHP has worked, albeit on a different server. Please try the drivers below if having a similar problem:
http://www.microsoft.com/download/en/details.aspx?id=20098

Categories