run database sql query from php just like from phpmyadmin [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Does anyone here have a ready made PHP file (script) which can connect to the database (by inserting, host,dabasename,user,pas) and then be used to run SQL queries. For example by putting the query in a variable and then run it. This would be the same kind of queries which can be run from phpmyadmin.

If you're asking how to use a MySQL database in PHP, I suggest learning about PDO:
<?php
$pdo = new pdo("mysql:host=localhost,dbname=YourDatabase","Username","Password");
?>
and submitting would go as follow:
<?php
//Unsafe
$unsafeSubmit = $pdo->query("INSERT INTO `myTable` VALUES(`id`,'".$variable1."','".$variable2."')");
//Safe
$submitInformation = $pdo->prepare("INSERT INTO `myTable` VALUES(`id`,:varOne,:varTwo)");
$submitInformation->bindValue(":varOne",$variable1);
$submitInformation->bindValue(":varTwo",$variable2);
$submitInformation->execute();
?>
With reading it with the SELECT query.
I suggest reading the documentation on PHP.NET

You should read up on how to do this, there are multiple ways like PDO or MySQLi
documentation mysqli on php.net
documentation pdo on php.net
These are two very well used, well supported and built in libraries in PHP which will allow you to execute queries from PHP. It's one of the first things I learned at school (deprecated mysql) so you should be fine reading up on those two.

Ok i found a quick solution using Sidney Liebrand links. Thanks
<?php
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
#mysql_select_db($database) or die( "Unable to select database");
$query= /* query */ "";
mysql_query($query);
mysql_close();
?>

Related

Simple idea behind a database for a single website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a website. I'm using MySQL Workbench 6.3. I have MySQL installed.
How hard can it be to send and receive data from this database, from the website? I don't know php yet, but I can learn it if that's necessary.
What I want is simply to, for example, have a form on a website which sends it's information to the database. I understand about the columns in the database, and I've created a database table thing on the MySQL workbench, but I don't know how to host this database, or how to access it from my website.
Even just some good links would be helpful, as I haven't found any.
You actually can Google but you can go try to learn at the links below:
w3schools.com
php.net
And you need to learn sql too. For sql, this links can help you:
w3schools.com
tutorialspoint.com
Hope this links will make your job easier.
And a quick tutorial by me:
mysql_* commands are no longer available. Use mysqli or PDO.
Connecting To Your Database:
Using mysqli
<?php
$conn = new mysqli($servername, $username, $password);
?>
Using PDO:
<?php
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
?>
Hope everything will work fine, happy coding!

MySQL determining which database to use [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am a beginner with MySQL. I have this code and I would like an explanation on how the function knows which database to use since $conn and $db are defined?
$conn = mysql_connect("localhost","primeb5_mysql","***");
$db = mysql_select_db("primeb5_unigis");
$query = "SELECT * FROM lesson3";
$result = mysql_query($query);"
From PHP manual:
http://php.net/manual/en/function.mysql-query.php
The MySQL connection. If the link identifier is not specified, the
last link opened by mysql_connect() is assumed.
So, In case you don't specify the connection (second parameter) to the mysql_query() function, the last one is used.
On the side note, I'd like to notify you, that mysql_* functions have been deprecated in PHP 5.5.0. Do not use them, because if you do, your site might stop working soon.
mysql is deprecated use mysqli or PDO instead
You don't have to use an PHP function to select your database
just use this
mysqli_query("SELECT * FROM primeb5_unigis.lesson3");
or join example between multiple databases after ON missing...
mysqli_query("SELECT * FROM database1.table1 INNER JOIN database2.table2 ON ...");
edit
i think topicstarter means connection to database but i leave the answer could be helpfull

php oracle integration where to begin? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
We have an up and running server with php and mysql. We want to use Oracle db as well as the mysql(for performance issues).
What can be the steps to implement oracle to php? Can you give me a head start on where to begin?
You need to use oci driver for oracle connectivity with php, You can use 2 different way for php & oracle connectivity. First way to enable php_pdo_oci extension and 2nd install php_oci8 or php_oci8_11g depends on oracle version. For the starting purpose you can check you connection with sample code below for php_pdo_oci extension.
$tns ='tns:port/dbname';
$db_username = 'username';
$db_password = 'password';
try{
$db = new PDO("oci:dbname=".$tns,$db_username,$db_password,array(PDO::ERRMODE_EXCEPTION => true));
}
catch (PDOException $e)
{
die("getConnection: " .$e->getMessage());
}
$stmt = $db->query("SELECT FIELD_NAME FROM TABLE WHERE ID=1");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo '<pre>';
print_r($row);
If want to use core php you can use here
Else if you can use CodeIgnitor framework which provide ORM support with many database like mysql, oracle, etc...

PHP Open Source MySQL Query Builder? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Do you know an open source Mysql Query Builder made in PHP please ?
Like "Query Builder for MySQL by dbForge "?
http://www.devart.com/dbforge/mysql/querybuilder/benefits.html
MySQL Query Builder
MySQL Workbench
These are just two.
Try using SQLyog's powerful Query Builder. Although SQLyog is not in PHP, but it is really easy and intuitive to use.
i think that the query builder is a php code that simplifies the writing of sql queries like this https://github.com/lytc/mysql-query-builder/tree/master/library/Qb
for light websites it's useless to use an ORM so a query builder should do it , or even a DBAL ,
it helps a lot with manipulating the data when retrieved and inserting data to the data Base .
The best one I found is QueryBuilder

Is there a tool that can transform a static SQL string into valid Drupal db query code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am wondering if there is some tool available, that will take as input a SQL command, and as output will return valid Drupal code that can be used in the Drupal Api?
EDIT
The idea is I have large, 25 lines of SQL commands ready to be used on the database. And they are somehow complicated, so I am wondering how could I rewrite them with a tool to use the object members on the db_query to do the same stuff as my large SQL command line.
i assume there's no such tools.
Just read:
sql coding conventions
http://drupal.org/writing-secure-code
This might save some time, depending on what you are trying to do with SQL.
http://drupal.org/project/views
Plain 'ol non-Drupal SQL will still work in db_query ... it's just not a best practice since the database API can't retool the SQL to work in any supported environment, and doesn't take advantage of Drupal's SQL injection protections, among other things.
But it still works.
If you're going to use the SQL in a known environment (e.g. a system where these commands are already in use), I'd say just use them as they are for now and gradually convert them over to Drupal standards as new code is developed.
(Of course, if this code is meant to be distributed to other environments, you'll want to put in sweat equity and convert the strings, or write a tool to do so)

Categories