answersLogoWhite

0


Best Answer

Here is a simple script that you can do to run a MySQL query after you have set a database up.

<?php

// Database Settings

$db['hostname'] = "localhost";

$db['username'] = "<db username>";

$db['password'] = "<db password>";

$db['database'] = "<db name>";

// Connect to MySQL

$connect = mysql_connect($db['hostname'], $db['username'], $db['password']);

// Select Database

mysql_select_db($db['database'], $connect);

// Do MySQL Query

mysql_query("INSERT INTO table_name SET field_name = '1234567890'");

// Close MySQL

mysql_close($connect);

?>

Obviously you will need to use your own MySQL settings and database details, but this gives you a general overview of how you can do it.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you run a MySQL query from PHP file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is an insert query in PHP and MySQL?

In a database table, the INSERT INTO statement is used to insert new rows. Let's create a SQL query with acceptable values using the INSERT INTO statement, and then run it by passing it to the PHP mysqli query() function to insert data into the table. To learn more about data science please visit- Learnbay.co


Why you need wamp server to run php file on web browser?

PHP Web Development and Running PHP application requires a lots of efforts and tools. For running PHP file on web browser we required a compiler which can convert php files to HTML files. And a web server like Wamp helps a php file to convert it to PHP. Basic Component of WAMP Server are : Wnodows : Which is our OS. Apache : Web server for responding with web pages. MySql : Databases Query and PHP


Can you run PHP and MySQL on Linux?

Yes.


How do you run a MySQL query involving many fields in PHP?

A mysql query can be run with the mysql_query(); function. Unfortunately, php allows you to run a maximum of one query each time. A possibility is to write all your queries to an array();, and then have them applied in a foreach(); loop.


How do you run php file?

Either you could download latest version of php, mysql &amp; apache server or better you just need to install xampp. Versions of it are available for all OS


Can you open php file in your PC?

Since a PHP file basically is a text file, yes. But beware - opening and running a PHP file are not the same. If you want to run a PHP file, you will need a webserver with PHP module enabled.


How to solve what if your php installation appears to be missing the mysql extension which is required by wordpress?

Ideal thing to do would be to delete all your installation &amp; install a single WAMP/LAMP server. It combines all the features necessary to run php including windows/linux, apache, mysql &amp; php


How do you run sql on terminal in linux os?

mysql -u user -p -e 'SQL Query' database


Is PHP runable in Linux?

PHP can run on any major operating system just like java as long as you have an interpreter. Try installing a LAMP (Linux, Apache, MySQL, PHP) server &amp; you should be able to run php on your pc/server. There are some IDE's which would allow php development on linux os


How do you output a star using PHP?

type this in a file save it as something.php and then run it &lt;?php echo '*'; ?&gt;


How do you run a PHP file?

you need to be running a lamp / wamp server on your machine... point the browser to the file and it wll run. you can also use command line to run php scrips when you have lamp/wamp installed


How run php program in wanp server in window?

Once you install wamp server. Any file with php extenstion like xyz.php you put in www folder will be executed as PHP file.