I am beginner in mysql database. I am trying to create an online database application in android. This is a user registration application. I have tested this app with emulator and it succesfully inserting the entered data into database. At the same time tested this app with a real android device and can't insert the data into the database. Is it possoble to do? How can I do this with the same offline server. I am using wampserver version 2.5. My php code given below
<?php
$servername = "localhost";
$username = "micro";
$password = "micro";
$dbname = "insert_user";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
$name=$_POST['user'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$flag['code']=0;
$sql = "INSERT INTO user(name,pass,email)VALUES('$name','$pass','$email')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
you need a REST api
try this tutorial, maybe help
http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/
You have to connect your real device with USB cable.
If you had connected with USB try to run your IP in a browser of the phone as well as in PC If it opens the wamp server then run the application. If not then click on wamp server's green icon below the screen go to apache and then open httpd.conf file and find(Deny for all) change it to allow for all.
Related
I have recently started working with amazons cloud specifically the elastic beanstalk and RDS components.
I have setup my EC2 SERVER
I have setup my RDS INSTANCE
I have also setup my elastic beanstalk app, a single page that needs to query a my database please see below
<?php
$servername = $_SERVER['RDS_HOSTNAME'];
$username = $_SERVER['RDS_USERNAME'];
$password = $_SERVER['RDS_PASSWORD'];
$dbname = $_SERVER['RDS_DB_NAME'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Email: " . $row["Email"]. " - Name: " . $row["fname"]. " " . $row["lname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
I have also been able to access my mysql database created on RDS and accessed it with work bench.
the problem I am having presently with my application hosted using beanstalk is when I try accessing my application I am getting
Connection failed: Connection timed out error
please I need help about getting this solved I am new to this whole amazon cloud thing, but its really exciting I must say.
Thanks
The only tutorials I could find used unfamiliar alternative resources, like app engine, composer, github, proxies, other plugins.
Isn't it possible to simply connect to it using pure PHP?
For example, in the following code would I need to modify to get data from Google Cloud SQL?
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
Google App Engine connects from inside of Google servers to the Cloud SQL instance via proxy, but the Cloud SQL instance is just a managed MySQL instance. So, if you want just to connect from the outside with PHP code and without a proxy, then you just need to authorize your IP (here: https://cloud.google.com/sql/docs/mysql/connect-external-app#appaccessIP) in the Cloud SQL instance.
And then, you should modify the code to change “localhost” to your Google Cloud SQL instance public IP (with its proper username, password and dbname). You can find the public IP here: http://console.cloud.google.com/sql/instances/
But, if you still want to have a look around PHP on Google App Engine, check that link https://cloud.google.com/appengine/docs/standard/php/cloud-sql/using-cloud-sql-mysql
I'm encountering an issue when I try to use php to create a database. I've google around, ensured that the user has permission to create a database and it still doesn't work.
I'm able to use PHP to create and modify tables once I create the database manually, but I'd like this code to run in PHP for personal reasons.
Here's the code, just in case I'm missing something.
*edit: grammar
<?php
$servername = "localhost";
$username = "user";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
//Create database
$sql = "CREATE DATABASE inkflow_backend";
if ($conn->query($sql) === TRUE){
echo "Database created successfully, continue.";
} else{
echo "Error creating database: " . $conn->error . "Please contact the developer or your network administrator.";
}
//Close connection
$conn->close();
?>
Review the quotes that you're using when printing a link to setup2.php.
They are causing a syntax error. Just putting a backslash before them would solve the problem:
<a href=\"setup2.php\" ...
I am not sure why I am getting this connection failed error. I am sure that the sever where the database is located is "localhost:3306". I'm currently using cPanel to access myAdmin.
My php code is
<?php
$server = "localhost:3306";
$username="root";
$password="";
$dbname ="mommyinfo";
$conn = new mysqli($server, $username, $password, $dbname);
if ($conn-> connect_error){
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT title, dateposted FROM post";
$result = $conn->query($sql);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["title"] . $row["dateposted"] . "<br>";
}
}else {
echo "More posts coming soon!";
}
$conn->close();
?>
At the top of PHP My Admin it says:
Server: localhost:3306 »Database: mommyinfo »Table: post
My goal is to get the five most recent posts to display in a div on my website. I've looked it up and I can't seem to find an answer that fixes it. Thanks in advance!
Remove the port number from the configuration file , just keep the mysql server as localhost and then try.
The tasks are:
restart your server.
You review if the service the mysql is starting
you quit the port
Or verify with ip address without any port or verify your port
If in services don't restarting else you stop the mysql server
I just made my own wamp server on my computer to handle twitch donations for a friend. The friend has a program that I made using c# that connects to the my server and reads the database. This works fine, the program reads my database just fine and lists the entries. BUT I have made a php website to send the entry (a new donation) to the database but I receive a connection timed out error just seconds after I press the button... my mysql server is set to allow every user and host with the correct password. I used the same IP user and password as on the c# program!
I can't figure out why the damn php website hosted on one.com can't connect!!
this is my code:
<?php
if (!empty($_GET['act'])) {
$servername = "81.83.95.34";
$username = "root";
$password = "mypassword";
$dbname = "tbc";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("server failed: " . $conn->connect_error);
}
$sql = "INSERT INTO donations (donations)
VALUES ('1')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
} else {
?>
can anyone help me?
thank you very much!