Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP XAMPP Config

I try to connect my php website with a XAMPP Server so I can access my MySQL database. Any Ideas how the config has to look like, because I’m rather stuck with this one.

I tried to make a config but it didnt really work. I’ll post my current config below:

<?php
    try {
        global $con;
        $server = 'localhost:3307';
        $user = 'root';
        $schema = '';

        $con = new PDO('mysql:host='.$server.';schema = '.$schema.';charset=utf8', $user);
        $con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    } catch(Exception $e) {
        echo $e->getCode().': '.$e->getMessage();
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think missing the password param after the user. Unfortunately you didnt provide the error, but maybe your error is the blank $schema param. You wont connect to a schema, if you dont put the name of the schema in there, so you whould have to use <use [name of schema]> to connect to it.

<?php
 try
 {
     global $con;
     $server = 'localhost:3307';
     $user = 'root';
     $pwd = '';
     $schema = '';

     $con = new PDO('mysql:host='.$server.';schema = '.$schema.';charset=utf8', $user,$pwd);
     $con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
 echo $e->getCode().': '.$e->getMessage();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading