loading but not showing

prescot

New member
I run phpinfo() and it loads the PHP configuration BUT "Configuration File (php.ini) Path" = no value!
It loads "mysqlnd" by default even I specified in the extension to load "mysqli" and "pdo_mysql" but it only shows PDO but it says "PDO drivers" = no value!
At the same time I run this:

phpinfo(); // it does load the configuration from the correct location BUT the script below says "not loaded"!?
$inipath = php_ini_loaded_file();

if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}

and I get this output:
A php.ini file is not loaded

2)
Also, the connection "$dsn = new PDO('mysql:host=localhost;dbname=mydb', $username, $password);" is not recognized, I get an error.
try{
$dsn = new PDO('mysql:host=localhost;dbname=mydb', $username, $password);
$dsn ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
print $e->getMessage();
}

Warning: Undefined variable $dsn in C:\...\index.php on line 41

Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\...\index.php:41
Stack trace: #0 C:\...\index.php(18): number_of_accounts('krupta')
#1 {main}thrown in C:\...\index.php on line 41

Very likely the "Fatal error" is the result of not recognizing ("$dsn") link. This worked while runnning Php7, now I am in Php8.
Anyone would know what is going on? Thanks much.
 
I run phpinfo() and it loads the PHP configuration BUT "Configuration File (php.ini) Path" = no value!
It loads "mysqlnd" by default even I specified in the extension to load "mysqli" and "pdo_mysql" but it only shows PDO but it says "PDO drivers" = no value!
At the same time I run this:

phpinfo(); // it does load the configuration from the correct location BUT the script below says "not loaded"!?
$inipath = php_ini_loaded_file();

if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}

and I get this output:
A php.ini file is not loaded

2)
Also, the connection "$dsn = new PDO('mysql:host=localhost;dbname=mydb', $username, $password);" is not recognized, I get an error.
try{
$dsn = new PDO('mysql:host=localhost;dbname=mydb', $username, $password);
$dsn ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
print $e->getMessage();
}

Warning: Undefined variable $dsn in C:\...\index.php on line 41

Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\...\index.php:41
Stack trace: #0 C:\...\index.php(18): number_of_accounts('krupta')
#1 {main}thrown in C:\...\index.php on line 41

Very likely the "Fatal error" is the result of not recognizing ("$dsn") link. This worked while runnning Php7, now I am in Php8.
Anyone would know what is going on? Thanks much.
 
Is there anyway to alter the Php path on windows?
Right now by default it is set "c:\php\.." BUT if I want to be in "c:\mydir\php\..", can I set the path or do I have to have my own script and call the script that would call the php directory then? Is that something I can set in ".conf" file? Thanks
 
try to locate php.ini correctly, Use php --ini for loaded configuration files.
Make sure the path declared for php.ini is correct.
check if PDO is enabled in phpinfo() output, you need to enable it first.
you need to review your DNS format, mysql:host=localhost;dbname=mydb
mysqlnd default driver should not be preventing PDO connections
 
  1. phpinfo() & Extensions:
    • Check if extension=mysqli & extension=pdo_mysql are enabled in the correct php.ini (use php --ini to find it).
    • Restart your web server after enabling.
  2. PDO Connection:
    • Ensure pdo_mysql is loaded (check phpinfo()).
    • Move new PDO inside the try block.
    • Use $dsn->prepare() instead of $dsn->prepare;.

Remember to adjust paths and details based on your specific setup.

try {
$dsn = new PDO('mysql:host=localhost;dbname=mydb', $username, $password);
$dsn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Use $dsn to prepare statements here
$stmt = $dsn->prepare("SELECT COUNT(*) FROM accounts WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$count = $stmt->fetchColumn();

} catch (PDOException $e) {
print $e->getMessage();
}
try this code i hope it will benificall for you
 
Back
Top