i have a problem about getting data from oracle database. How to get data in utf-8? browser shows symbols with echo, but data from oracle has ? marks instead of letters
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
</head>
<?php
$tns2 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521)) (CONNECT_DATA = (SID = sidname)))";
if ($conn = oci_connect("user","pass", $tns2))
{
echo "YAY!";
//oci_close($conn);
}
else
{
die("Nesiseka");
}
$stid = oci_parse($conn, 'SELECT * rowname where rownum<=10');
oci_execute($stid);
oci_close($conn);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
echo"įęėšųį";
?>
Simple solution. Only add 'AL32UTF8' to line if ($conn = oci_connect(username,pass, $tns2 , 'AL32UTF8')) Everything works now.
Thank you for help
Use this to make database connection:
$conn = oci_connect(username,pass, $tns2 , 'AL32UTF8')
set php encoding to utf 8
mb_internal_encoding("UTF-8");
link for more
http://php.net/manual/en/function.mb-internal-encoding.php
Related
I want to add a "download to Excel" button on a website.
I have built a search engine using PHP and mySQL.
When I search a keyword a table appears, I want this table to be
I have tried solution on this website but the data wouldn't go in the right cell!
Thanks for your help!!
<?php
$dbhost = 'xxx';
$username = 'xxx';
$password = 'xxx';
mysql_connect("$dbhost" , "$username", "$password" );
mysql_select_db("Data") or die("could not find the database!");
$output = '';
if(isset($_GET['search']))
{
$searchkey = $_GET['search'];
$query = mysql_query("SELECT * FROM Linkedin WHERE email LIKE '%$searchkey%' ") or die("Could not search");
$count = mysql_num_rows($query);
if ($count == 0)
{
$output = 'There was no search results !' ;
}
else
{
echo '<table class="table table-striped table-bordered table-hover">';
echo "<tr><th>Email</th><th>Hashkey</th><th>Breached account</th></tr>";
while ($row = mysql_fetch_array($query))
{
$email = preg_replace('/(' . $searchkey . ')/i', '<mark>\1</mark>', $row["email"]);
$hashkey = $row['hashkey'];
echo "<tr><td>";
echo $email;
echo "</td><td>";
echo $hashkey;
echo "</td><td>";
echo "Linkedin";
echo "</td></tr>";
$output = '</table>';
}
echo '<div>'."$count results were found for '$searchkey'.".'</div>'.'</br>';
}
echo $output;
}
?>
Use jQuery datatables for the purpose. It is easy and elegant.
https://datatables.net/extensions/buttons/examples/initialisation/export
I am doing a project and would be eternally grateful for help in getting my URl's to link. I have tried looking around to no avail. I have a database (4columns). The last one (link1) should link to videos with the specified URL.When the table comes up the URL's are not clickable (is there a way to simplify this say "click me"?). Here is my code. I've also attached an image of the table. This is really busting my brains, thanks.
<?php
$con = mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM videos";
$result = mysqli_query($con, $sql);
echo "<table>";
echo "<tr>
<th>topic1</th>
<th>subject1</th>
<th>link1</th>
</tr>";
while( $row = mysqli_fetch_array( $result)) {
$topic1 = $row["topic1"];
$subject1 = $row["subject1"];
$link1 = $row["link1"];
echo "<tr>
<td>$topic1</td>
<td>$subject1</td>
<td>$link1</td>
</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Table output
Try this:
<?php
$sql = "SELECT * FROM `videos`";
$result = mysqli_query($con, $sql);
?>
<table>
<?php
while($row = mysqli_fetch_assoc( $result)) {
?>
<tr>
<td><?php echo $row['topic1'];?></td>
<td><?Php echo $row['subject1'];?></td>
<td><a href="<?php echo $row['link1']; ?>" target="_blank">Click me</td>
</tr>
<?php } ?>
<table>
Or you can also use do while loop:
do{
echo '<tr>';
echo '<td>'.$row['topic1'].'</td>';
echo '<td>'.$row['subject1'].'</td>';
echo '<td><a href="'.$row['link1'].'" target="_blank">Click me</td>';
echo '</tr>';
} while($row = mysqli_fetch_assoc( $result);
I added the target attribute to open the link in a new window.
I looked at your code and i found a couple errors.
change $con = mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test"); to $con = new mysqli("localhost", "feedb933_charles", "pass100", "feedb933_test");
Then change if (mysqli_connect_errno()) to if (mysqli_connect_error()) {
Then change
$sql = "SELECT * FROM videos";
to
$sql = "SELECT topic1, subject1, link1 FROM videos";
or if you want to select one row
$differentvalue = ""; // value to run
$sql = "SELECT topic1, subject1, link1 FROM videos WHERE difvalue = ?";
difvalue is the value different frm the rest so the php code knows what to grab.
Using stmt means no sql injection
Add:
$stmt = $con->stmt_init();
if (!$stmt->prepare($sql))
{
print "Failed to prepare statement\n";
}
else
{
}
Then in side if (something) { } else { IN HERE }
(if you have WHERE diffvalue) Add:
$stmt->bind_param("s", $differentvalue); // $stmt->bind_param("s", $differentvalue); if text, $stmt->bind_param("i", $differentvalue); if integer
Then
Add:
$stmt->execute();
$list = $stmt->fetchAll();
then outside the if (something) { code } else { code }
Add:
echo "<table><tr><th>topic1</th><th>subject1</th><th>link1</th></tr><tr>";
foreach ($list as $row => $new) {
$html = '<td>' . $new['topic1'] . '</td>';
$html .= '<td>' . $new['subject1'] . '</td>';
$html .= '<td>' . $new['link1'] . '</td>';
echo $html;
}
echo "</tr></table>";
If you are still having problems goto the links listed
http://php.net/manual/en/pdostatement.fetchall.php
http://php.net/manual/en/mysqli-stmt.get-result.php
http://php.net/manual/en/mysqli-result.fetch-all.php
Hope this helps
<?php
$con=mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM videos";
$result = mysqli_query($con, $sql);
echo "<table>";
echo "<tr>
<th>topic1</th>
<th>subject1</th>
<th>link1</th>
</tr>";
while( $row = mysqli_fetch_array( $result)) {
$topic1 = $row["topic1"];
$subject1 = $row["subject1"];
$link1 = $row["link1"];
echo "<tr>
<td>$topic1</td>
<td>$subject1</td>
<td>$link1</td>
*//this href will give u the link as u asked. //be sure you store proper url. In case of exact video name saved in column thn can make the url for your web output. //ex:<a href="http://example.com/'.$link.'.extension">*
</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I want to get some data from my oracle database into php through a html form where I search by a string which exists into a column. I have the following php code and the search form retuns nothing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[A-Z0-9]+/", $_POST['name'])){
$name=$_POST['name'];
// Connects to the XE service (i.e. database) on the "localhost" machine
$conn = oci_connect('user', 'pwd', 'localhost/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, 'SELECT deejays.name,available_dates.data,available_dates.venue,available_dates.location FROM deejays,available_dates WHERE deejays.name LIKE '%W&W%' and pk_id=fk_id');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
<body>
</body>
</html>
The result I want is for i.e the following:
You need to modify your query to include bindable parameters. Here is part of example 4 from the documentation for the oci_bind_name function, which you simply need to adapt to suit your application:
$sql = 'SELECT last_name FROM employees WHERE department_id = :didbv ORDER BY last_name';
$stid = oci_parse($conn, $sql);
$didbv = 60;
oci_bind_by_name($stid, ':didbv', $didbv);
oci_execute($stid);
while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) {
echo $row['LAST_NAME'] ."<br>\n";
}
The documentation includes a very good description of what binding is, how to do it, and why it's important for application performance and security.
i have a problem displaying the result of a SQL query (against Oracle DB). My web page code is below. I am using tnsnames and run the webserver and the page on the oracle db server itself. Running the query in sqlplus/sql developer works fine.
TNSNAMES:
testdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testdb)
)
)
The page displays the 2 variables and afterwards directly the footer.
How can i display the returned data? Can somebody please help me?
Thanks
<head>
<title>Reports</title>
<link href="Site.css" rel="stylesheet">
</head>
<body>
<?php include("Header.php"); ?>
<div id="main">
<h1>Report1</h1>
<h2>Report2</h2>
<p>Report3</p>
<?php
if (isset($_GET['var1'])) {
$var_storenr = $_GET['var1'];
}
if (isset($_GET['var2'])) {
$var_storearea = $_GET['var2'];
}
echo "<p>Var 1: " . $var_storenr . "</p>";
echo "<p>Var 2: " . $var_storearea . "</p>";
$db_user='testusr';
$db_pass='testusr';
$db_name='testdb';
$conn = oci_connect($db_user, $db_pass, $db_name);
$query = 'select id_store, store_des from np_stores where id_store in ('.$var_storenr.') and id_region = '.$var_storearea.';';
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, $query);
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
<?php include("Footer.php"); ?>
</div>
</body>
i have figured it out. It was a problem with the oracle connection, mainly PHP and x64 Oracle client.
installed x32 client and works fine.
Thanks,
I am trying to write a page in php with the goal of counting the specified data from the database and showing that data. It seems like a simple enough task, but I cannot get this to work correctly and I'm at the limits of my very limited PHP/SQL knowledge. This is my code for the whole page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Counter Test</title>
</head>
<body>
<div id="counter">
<?php
$advance = "(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xx.xx.xxx)(PORT = 1521)))
(CONNECT_DATA =
(SERVICE_NAME = domain.domain)))";
$conn = oci_connect('xxx', 'xxx', xxx);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, 'SELECT count(distinct(b.id_number)) as total FROM bio b WHERE (b.alum_memb_type) is not null AND b.record_status_code NOT IN ('D', 'X', 'R')' );
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
</div>
</body>
</html>
You can expect one result back, so don't have to fetch in a loop.
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
$count = $row['total'];