I keep getting this error:
Fatal error: Uncaught Error: Call to undefined function
mysqli_connect() in C:\Apache24\htdocs\asd.php:2 Stack trace: #0
{main} thrown in C:\Apache24\htdocs\asd.php on line 2
when simply running any mysqli cmd in any php file e.g :
<?php $con = mysqli_connect('localhost','my_user','my_password','my_db'); ?>
I have already enabled the extension in my php.ini file and I've been trying to figure this out for a while and I just can't.
Any help would be greatly appreciated.
Can you try this code below:
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
And let me if it works thanks.
Related
I'm using php to validate forms and connect to my database but I get Fatal error: Uncaught Error: Call to undefined function pg_connect() even though I've uncommented these extension in my php.ini file
extension=pdo_pgsql
extension=pgsql
and restarted my Apache server several times. I still get the same error. I've tried everything and am now at loss. can yawl please help.
<?php
$conn= pg_connect("$host=####### $port=#### $dbname=######## $user=####### $password=######3");
if ($conn == True);
echo 'connection sucessful'
else
die (echo 'connection succesful');
?>
I imported the proper mongodb.dll file in php/ext and also configured php.ini but it seems that I can't connect to mongodb via my php code. Example
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
?>
Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\xampp\htdocs\date\include\db2.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\date\include\db2.php on line 3
I'm trying to enable SQL Drivers.
I'm using xamp my version of php is 7.1.10 and Architecture x86
I installed the version 4 of SQL Drivers, and moved the files to the extesions folder and I have this in the php.ini
extesion=php_sqlsrv_7_nts_x86.dll
extesion=php_pdo_sqlsrv_7_nts_x86.dll
And I'm getting this error
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in
C:\xampp\htdocs\diplomado\conection.php:4 Stack trace: #0
C:\xampp\htdocs\diplomado\index.php(17): include() #1 {main} thrown in
C:\xampp\htdocs\diplomado\conection.php on line 4
and this is my php file
$serverName= "localhost";
$conectionInfo = array("DataBase"=>"prueba","UID"=>"Root", "UPW"=>"");
$con = sqlsrv_connect($servername,$conectionInfo);
if ($con){
echo "Succesful";
}else{
echo "failed";
}
?>
$con = mysql_connect('HOSTNAME', 'USER', 'PASSWORD');
I run with the above code and it shows the error below
Fatal error: Uncaught Error: Call to undefined function
mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php on
line 3
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php on
line 3
If you are use PHP 7+ MYSQL no longer exist, try MYSQLi
if you are using any 5.x version, follow below
Try checking if the PHP MySQL extension is enabled or not.
<?php
phpinfo();
?>
if you cannot find mysql extension there, theme mysql extension is not enabled.
Locate php.ini file, and edit it.
find the line
;extension=php_mysql.dll
and remove ; from the line
extension=php_mysql.dll
I have a php file(conn.php) which has the following contents:
<?php
$conn = oci_connect('mdl_img_tst', 'mdl_tst_usr', 'draa.uofl.com');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
?>
Running this from the command line it returns following two errors:
Failed loading /usr/lib/php/extensions/no-debug-non-zts-20090626/5.3/xdebug.so: dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/5.3/xdebug.so, 9): image not found
PHP Fatal error: Call to undefined function oci_connect() in /Users/crdc/Sites/conn.php on line 5
What could be the possible reason for that?
UPDATE: I added a line extension=oci8.so and now there is a different error. Now it seems like oci8 is installed correctly but it has some problem with connection string.
PHP Warning: oci_connect(): ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA in /Users/crdc/Sites/conn.php on line 5
PHP Fatal error: ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA in /Users/crdc/Sites/conn.php on line 8
Any idea on that?
I would recommend verifying that OCI8 has actually been loaded by PHP.
Run this script
<?php
phpinfo();
?>
And verify that OCI8 is shown as a loaded plugin.