im trying to connect php and msaccess
Im using the code below in connecting php and ms access and so far it working fine when i add System DSN to fetch database locally
but when the database is in remote location i receive the message connection failed
<html>
<body>
<?php
$conn=odbc_connect('northwind','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
{
$compname=odbc_result($rs,"CompanyName");
$conname=odbc_result($rs,"ContactName");
echo "<tr><td>$compname</td>";
echo "<td>$conname</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>
Just for information im working this is old server with winserver 2003 installed
Related
I wrote this code for the ODBC connection. But, I'm getting like this error. My DB is an MS Access database. Please, can anyone help me?
<html>
<body>
<?php
$conn=odbc_connect('finance','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM Customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Name</th>";
echo "<th>CustomerID</th></tr>";
while (odbc_fetch_row($rs))
{
$Name=odbc_result($rs,"Name");
$CustomerID=odbc_result($rs,"CustomerID");
echo "<tr><td>$Name</td>";
echo "<td>$CustomerID</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>
This is my error.
Warning: odbc_exec(): SQL error: [FINANCE ODBC]Base table:Customers not found., SQL state S0002 in SQLExecDirect in C:\xampp\htdocs\odbc\index.php on line 11
Error in SQL
I currently working on PHP app which is run on blumix and I have used the following code to connected to this app to Compose for MySQL.But the connection has failed and shown me an error message on the browser " lastapp.eu-gb.mybluemix.net is currently unable to handle this request. HTTP ERROR 500"
the code below has been used to create the connection.
enter link description here enter image description here
When executing this code I could connect to your database:
<?php
$conn = mysqli_connect("sl-eu-lon-2-portal.11.dblayer.com", "admin", "FWXJWBNMHRFNUOVG", "compose", 27707);
if (!$conn) {
echo "Error!";
die();
}
else {
echo "Success!<br>";
echo "Details: ".mysqli_get_host_info($conn);
}
mysqli_close($conn);
?>
I have Ubuntu 16.10 x86_64 x86_64. I installed LAMP to program in PHP and to create databases. In my php program I want to connect to my local database for creating a table ( in HTML ) with the data of any row of the table.
The problem is that when I open the php file( localhost/file.php ) through firefox ,the browser doesn't charge anything. If thare were been an error during the connection with the database, It would have printed something in the browser.
Here the code:
<!DOCTYPE html>
<html>
<head><title> SQL & PHP </title></head>
<body>
<?php
$db = mysql_connect("localhost", "root", "password")
or die ("Non riesco a creare la connessione");
mysql_select_db("scuola")
or die ("Non trovo il DB");
$sql = "SELECT id_utente, nome_utente, password_utente, conta_pres FROM utenti WHERE conta_pres <> 0";
$ris = mysql_query($sql) or die ("Query fallita!");
echo "<TABLE><TR><TH>ID utente <TH> Nome utente <TH>Password<TH>Contatore visite</TR>";
while ($riga= mysql_fetch_array($ris))
{
echo ("<TR>");
echo "<TD>" . $riga["id_utente"];
echo "<TD>" . $riga["nome_utente"];
echo "<TD>" . $riga["password_utente"];
echo "<TD>" . $riga["conta_pres"];
}
mysql_close();
?>
</body>
</html>
I checked the syntax (using a website) of the code and thare aren't problems,even because I copied this one by a book. I read that mysql_connect has been deprecated, so I replaced it with new mysqli_connect but the error still remains: white page. I tried to put 2 echo, one before the connecting function and one after that. Only the first echo is printed on the screen. I tried to type in the terminal sudo apt-get install php5-mysql but there is an error:
The "php5-mysql" packet has not run to install
Can someone help me, please?
First of all use mysqli instead of mysql.
I think I have found the problem. When you call mysqli_select_db, it expects 2 parameters and you only specified one. Even though you have set the $db database connection, you need to specify which database you want to select the database name from.
So mysqli_select_db($db, "scuola") should do the trick.
And at the bottom close the connection specifying which connection to close. In your case it is: mysqli_close($db);
<!DOCTYPE html>
<html>
<head><title> SQL & PHP </title></head>
<body>
<?php
$db = mysqli_connect("localhost", "root", "password")
or die ("Non riesco a creare la connessione");
mysqli_select_db($db, "scuola") // see this line
or die ("Non trovo il DB");
$sql = "SELECT id_utente, nome_utente, password_utente, conta_pres FROM utenti WHERE conta_pres <> 0";
$ris = mysql_query($sql) or die ("Query fallita!");
echo "<TABLE><TR><TH>ID utente <TH> Nome utente <TH>Password<TH>Contatore visite</TR>";
while ($riga= mysql_fetch_array($ris))
{
echo ("<TR>");
echo "<TD>" . $riga["id_utente"];
echo "<TD>" . $riga["nome_utente"];
echo "<TD>" . $riga["password_utente"];
echo "<TD>" . $riga["conta_pres"];
}
mysqli_close($db); // see this line
?>
</body>
</html>
So I'm trying to connect my very basic android application to an apache server.
I went as far as downloading wampserver and have started coding the php files to connect and post (both separate files). While it is connecting to my database, it is failing to retrieve or to post data into the database using php.
<?php
require "init.php";
$name="Lucky";
$message="Getlow";
$sql_query="select * from post_its where name = '$name';";
$result= mysqli_query($con,$sql_query);
if(mysqli_num_rows($result)>0)
{
echo "Login Successful";
}
else
{
echo "Error";
}
?>
My php file for connecting to the database is given below:
<?php
$db_name="webappdb";
$mysql_user="root";
$mysql_pass="";
$server_name="localhost";
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
if(!$con)
echo Connection Error;
else
echo <h3>Connection Success</h3>
?>
In my browser when I try and run my post.php file, it shows me:
Connection Success ?>(followed by random chinese characters)
Please help!
How is it is can not create a database on phpMyAdmin? I connect to PHP just fine, no error message. But when I am trying to create a database so phpMyAdmin, I keep getting error. In case it matters I have one page with a <form> and has a submit to my second.php file where my database code is (second.php is shown below).
I am pretty much trying to display the database in phpMyAdmin but nothing shows up:
<html>
<body>
<?php
$con = mysqli_connect("localhost", "user", "password");
if(!$con){
echo "could not connect";
} else {
echo "good connection";
}
//creation of database
$sql= 'CREATE DATABASE project';
if(mysql_query($sql,$con)){
echo 'DB created succesfully';
} else {
echo 'error creating DB' . mysql_errno();
}
?>
</body>
</html>
One issue is you connected with mysqli and are using mysql the rest of the time. Pick 1 (not mysql) library and use only that.
if(mysqli_query($con, $sql)){
and
echo 'error creating DB' . mysqli_error($con);