Jump to content

Recommended Posts

Posted

Ca sa scutesc din spatiu si timp as vrea sa fac conectarea la baza de date dintr-un fisier extern care va fi numit connectdb.php

Ce trebuie sa adaug in fisierul connectdb.php si ce trebuie sa modific in fisierul existent?

 

Momentan arata asa:

		<?php
			$con=mysqli_connect("mysql3.000webhost.com","a5691033_cc","andrei123","a5691033_cc");
			// Check connection
			if (mysqli_connect_errno()) {
			  echo "Failed to connect to MySQL: " . mysqli_connect_error();
			}

			$result = mysqli_query($con,"SELECT * FROM p_capital");

			while($row = mysqli_fetch_array($result)) {
			  echo "<tr>";
			  echo "<td>" . $row['suma'] . "</td>";
			  echo "</tr>";
			}
			echo "</table>";

			mysqli_close($con);
		?>

  • Moderators
Posted

connectdb.php

<?php 

$con=mysqli_connect("mysql3.000webhost.com","a5691033_cc","andrei123","a5691033_cc");

if (mysqli_connect_errno()) 
{
	die("Failed to connect to MySQL: " . mysqli_connect_error());
}

?>

fisierul tau:

<?php

require_once('connectdb.php');

$result = mysqli_query($con,"SELECT * FROM p_capital");

$HTML = "<table>";

while($row = mysqli_fetch_array($result)) 
{
	$HTML .= <<<HTML
		<tr>
		<td>{$row['suma']}</td>
		</tr>
HTML;
}

$HTML .= "</table>";

echo $HTML;

mysqli_close($con);
?>

L-am scris direct in notepad, n-am stat sa vad daca-i bun.

  • Upvote 1

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.