in wamp:could not find driver in ms access using php., i already enable the require extension in PDO at php.ini
here is my code:
?php
try
{
$pdo = new PDO("dsn:msbrian");
}
catch (PDOException $e) {
echo $e->getMessage();
}
?>
Related
I'm trying to connect to my MySQL DB located on 192.168.23.140 from my Web Frontend on .23.139
Here is my code :
$servername = "192.168.23.140";
$username = "web";
$password = "rootnetwork";
$dbname = "test";
try {
$conn = new PDO('mysql:host=$servername; dbname=$dbname', $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
Here is what i get :
Connection failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
I've been looking for some answers on the internet but none of them work.
Thank you for your help
$variables are not expanded in a single quotes string literal, they are only expanded in a double quoted string literals.
So
$conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password);
You will also have to make sure that this MYSQL user account web is setup to allow connections from ip addresses that are not the ip of the machine running MySQL
I want to connect to a MySQL database from PHP but I can't because "authentication method unknown", I found many solution but all of them about creating a new user with the old password type, but according to the PHP documentation, it should support the new password type. So is it possible to use the new MySQL password type with PHP 7.2.7?
Versions
PHP: 7.2.7MySQL Server: 8.0.12
PHP Code
// Create connection
$conn = new mysqli($servername, $username, $password);
$conn->set_charset("utf8");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Result
Connection failed: The server requested authentication method unknown to the client
i trying to learn php but found an issue.. im using mamp on a windows PC. and when im trying to connect my php with mysql a get this error:SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES).....
in mysql i got the info username and password are 'root', host:localhost port:8889
and this is my code..
function connectToDb()
{
try{
return new PDO('mysql:host=localhost; dbname=tutorials','root','root');
}
catch (PDOException $e){
die ($e->getMessage());
}
}
any help will be appreciate.... thanks...
Use this it will work...
$dbhost = 'localhost:3306';
$dbuser = 'guest';
$dbpass = 'guest123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
// make the current db as your DB_Name
$db_selected = mysql_select_db('DB_Name', $conn);
add port number also to your code...
mysql:host=localhost:8889
And it will look like this
function connectToDb()
{
try{
return new PDO('mysql:host=localhost:8889; dbname=tutorials','root','root');
}
catch (PDOException $e){
die ($e->getMessage());
}
}
or your credentials will be incorrect ie, try the connection with password=' '.
I have tried
this code-
$query=mysql_query("insert into ims(emp_name,emp_id,department,subject,date,matter)
value('".$_SESSION['name']."','".$_SESSION['eid']."','".$_SESSION['dept']."','".$_POST['subject']."','".$_POST['date01']."','".$_POST['textarea2']."')") or die("Inenatry Error");
<?php mysql_close($query);?>
I got error:
Warning: mysql_close(): supplied resource is not a valid MySQL-Link resource in
mysql_close() accepts a connection resource as parameter
Suppose you have your connection like this
$connection = mysql_connect(...);
then use
mysql_close($connection);
For more information see this.
Warning : mysql_* is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used
you have to do something like
$db_conn = mysql_connect("localhost", "root", "******");
mysql_close($db_conn);
Well, you'd have to show us this line. Generally, though, using mysql_close() isn't needed - the connection is automatically closed when the script has finished executing.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
You are doing it wrong. mysql_close will take mysql connection resource not query object. So your code should like that.
$conn = mysql_connect('DB_HOST', 'DB_USER', 'DB_PASS');
mysql_select_db('DB_NAME');
$query = mysql_query("insert into ims(emp_name,emp_id,department,subject,date,matter) value('".$_SESSION['name']."','".$_SESSION['eid']."','".$_SESSION['dept']."','".$_POST['subject']."','".$_POST['date01']."','".$_POST['textarea2']."')") or die("Inenatry Error");
mysql_close($conn);
I have created a website that has a MySQL database. I'm using phpmyadmin and xampp. Now I have a website to upload the files to (using Filezilla). How do I upload the MySQL database to the server and connect it to the website? I'm guessing there is already a tutorial somewhere but I couldn't find it.
If you have your database file ready to upload then in phpmyadmin there is an import option as shown in the image below:
In order to connect it to your website will depend on your server side language choice...
Example with PHP to connect your website to your database (using pdo):
<?php
$dsn = 'mysql:dbname=name_here;host=127.0.0.1';
$user = 'root'; //change to your username
$password = '******'; //change to your password
try {
$pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
Once you have that at top of your PHP file you can connect. This one way to do it via PHP.