I'm testing a connection to mysql 5.1, with php5 on apache2 (windows).
I have made a regular php test connection page from a tutorial but I'm getting the error "mysql_connect" not defined.
In eclipse for php, I see the function defined under the language library. However when I make a page:
<?php
phpinfo();
?>
I don't see mysql functions or anything there; can someone tell me why? I thought PHP5 at the least would support MySQL, no?
The MySQL extension is probably not enabled. If you look through the php.ini file, you should be able to find the appropriate line. phpinfo() will show the location of the php.ini file.
there is php documentation
http://php.net/docs.php
mysql_connect
http://php.net/manual/en/function.mysql-connect.php
however mysql extension should be enabled in php.ini
(linux: /etc/apache2/)
Related
I'm trying to use SQL Server with PHP but I don't know how to install this feature. I have enabled extension=php_mssql.dll in my php.ini file but after restarting apache I got a error message saying that don't found the DLL file.
After much attempts I reinstalled XAMPP 1.81, and I'm starting now from zero.
Thanks for any help.
Edit MSSQL has been discontinued as of 5.3
I believe the correct driver is php_sqlsrv.dll.
http://www.php.net/manual/en/sqlsrv.installation.php
Here are the available functions: http://www.php.net/manual/en/ref.sqlsrv.php
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).
I am trying to make a connection between PHP and a SQL server's database. I'm running XAMPP, and I deleted the ; from extension=php_mssql.dll to enable the PHP extension by modifying the php.ini file.
When I run my script, however, PHP throws an error that says the function mssql_connect() doesn't exist.
What can I do to fix this?
So far xampp comes with MySQL and have not include Microsoft SQL Server (MSSQL)
As a general approach:
In the php.ini is an option
display_startup_errors = Off
Set that to On and call PHP (maybe from console).
It should tell you what went wrong then.
i am using sqlite_escape_string($str) to prepare sql statements for future use.
however, when i migrated my code to a new server, it says:
Call to undefined function sqlite_escape_string()
seems the Sqlite and everything is working in the new server, but i have error even for a sqlite_open().
Anyways, i just need to escape my $str to a sqlite safe sql statments, i dun even need to write to sqlite from PHP, so an
That sounds like the SQLite plugin is not enabled for PHP. Write <?=phpinfo()?> in a .php file, load it up on your server and see if SQLite is mentioned in the loaded plugins.
You need to uncomment the extension=php_sqlite.dll line by removing the semi colon right now your pdo_sqlite is enabled and sqlite_escape_string is a function of sqlite extension and sqlite_pdo will not work untill php_sqlite is enabled
I found the ans myself.
It is due to my server is a Centos 5.4, and sqlite support for php is not there.
The same case should exist in REL5 also.
see the 1st and 2nd latest comment in the link below:
http://www.php.net/manual/en/sqlite.installation.php
I solved it by recompiling my php and added the sqlite.ini file
For those who recently upgraded to 5.4+, note that the php docs say, this method is not available 5.4+
(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
So you would either need to manually compile it in, or look at PECL.
On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.
I've downloaded the "Instant Client Package - Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get
Fatal error: Call to undefined function oci_connect() in...
when running this code:
<?php
$conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>
I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?
You need the PHP extension, try the following on your Ubuntu:
(sudo) pecl install oci8
Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.
UPDATE:
Enter something like this when it asks you for ORACLE_HOME:
instantclient,/opt/oracle/instantclient
I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.
HTH
I think you'll need to make sure that the $ORACLE_HOME/lib32 is in your $LD_LIBRARY_PATH, or else add that directory to the /etc/ld.so.conf file.
In the end, I downloaded Zend Core for Oracle and that worked.
http://www.zend.com/en/products/core/for-oracle