my code stock.com

Un simple SELECT

Snippet options

Download: Download snippet as php-mysql.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php
$enlace = mysql_connect('localhost', 'userBD', 'userBDpass');
if (!$enlace) 
{
    die('No se pudo conectar : ' . mysql_error());
}

$bd_seleccionada = mysql_select_db('bdname', $enlace);
if (!$bd_seleccionada) 
{
    die ('No se puede usar bdname : ' . mysql_error());
}

mysql_query ("SET NAMES 'utf8'");
$queryDB = "SELECT * from table";

$result = mysql_query($queryDB) or die('query did not go through');
if($result!=false)
{
	while ($rowEmp = mysql_fetch_assoc($result)) 
	{
		$data[] = $rowEmp;	
	}
}
echo json_encode($data,true);
?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.