 |
Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Comunitatea PHP Romania
|
| Subiectul anterior :: Subiectul următor |
| Autor |
Mesaj |
monk
Data înscrierii: 28/Noi/2004
Mesaje: 16
|
| Trimis: Dum Ian 16, 2005 11:33 pm Titlul subiectului: odbc tables stie cineva ? |
|
|
am citit
http://ro.php.net/manual/en/function.odbc-tables.php
dar n-am inteles cum pot afla ce tabele sunt in db
cum pot pune intr-un array numele tabelelor TABLE_NAME
am incercat
Cod: // conexiune
$tablelist=odbc_tables($odbc, 3); echo "<pre>";
while ( $tab = odbc_fetch_array($tablelist) )
{
print_r($tab);
}
echo "</pre>"; |
|
| Sus |
|
johnny
Data înscrierii: 31/Iul/2004
Mesaje: 904
Locație: Bucuresti
|
| Trimis: Mar Ian 18, 2005 5:15 pm Titlul subiectului: |
|
|
http://ro.php.net/manual/en/function.odbc-tables.php
Citat:
liquidicee at hotmail dot com
11-Mar-2001 06:02
Here's how to get a list of all the tables in your database.. with an actual example of how its done and how to get the results.. and you don't need to put in schema and all that other crap
$conn = odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (odbc_fetch_row($tablelist)) {
if (odbc_result($tablelist, 4) == "TABLE")
echo "" . odbc_result($tablelist, 3) ."<br>";
}
to understand what the above is doing,
use odbc_result_all($tablelist); this will show you EVERYTHING returned by odbc_tables() then you can look through it and see better how odbc_tables() works and what exactly it returns in the string to get a better idea on how to deal with it.
it would have saved me alot of time if i would have just taken a look at the full string returned by odbc_tables(), so i suggest you take the minute or two and look... here is an example of how to do it..which would have been helpful for me ;x.
<?php
$conn = odbc_connect("$database", "$username", "$password");
$tablelist = odbc_tables($conn);
while (odbc_fetch_row($tablelist)) {
echo odbc_result_all($tablelist);
}
?>
hopefully this will help some people.. i have alot more to add about this but no time :(
so again hope this helps.
Liquidice
|
|
| Sus |
|
monk
Data înscrierii: 28/Noi/2004
Mesaje: 16
|
| Trimis: Sâm Ian 22, 2005 1:49 am Titlul subiectului: |
|
|
trebuia 4 in loc de 3
Cod: if (odbc_result($tables, 4) == "TABLE" or odbc_result($tables, 4) == "VIEW" )
pentru a accesa o db ms access cu odbc
ex. catalog.mdb
Click : Start -> Settings -> Control panel -> Administrative Tools
Click pe tab-ul System DNS
Click Add -> select Driver MS Access (*.mdb) -> Finish
Data source name: numeconexiune - catalog - in cazul meu
Select - Database name - select catalog.mdb
Am realizat conexiunea odbc catalog spre fisierul c:\catalog.mdb
Click -> Advanced user : "root" passw:"" none
cod php conectare
<? // odbc.php
$odbc = odbc_connect ('catalog', 'root', '') or die( "Could Not Connect to ODBC Database!");
if (function_exists(odbc_fetch_array))
return;
function odbc_fetch_array($result, $rownumber=-1) {
if (PHP_VERSION > "4.1") {
if ($rownumber < 0) {
odbc_fetch_into($result, $rs);
} else {
odbc_fetch_into($result, $rs, $rownumber);
}
} else {
odbc_fetch_into($result, $rownumber, $rs);
}
$rs_assoc = Array();
foreach ($rs as $key => $value) {
$rs_assoc[odbc_field_name($result, $key+1)] = $value;
}
return $rs_assoc;
}
?>
cod afisare tabele si continut
<? // query.php
// conectare la odbc
// $odbc este conexiunea
include 'odbc.php';
if (isset($_GET['table_name']) )
{
$tabela = $_GET['table_name'];
} else {
$tabela = 'tabela1'; // tabela1 este in catalog.mdb
}
/*******************/
echo "<table><tr><td valign=top bgcolor=#f0f0f0 width=200 style='border-collapse:collapse; border:1px #333333 outset solid;' cellpadding=1 cellspacing=0>";
$tables = @odbc_tables($odbc) or die(odbc_error_msg());
$table_list = "<ul>
";
$i = 0;
while (odbc_fetch_row($tables)) {
if (odbc_result($tables, 4) == "TABLE" or odbc_result($tables, 4) == "VIEW" )
$table_list .= "<li><a href=\"query.php?table_name=" . odbc_result
($tables,
3) . "\">" . odbc_result($tables, 3) . "</a>
";
}
$table_list .= "</ul>
";
?>
<p><strong>Tables</strong>
</p>
<? echo "$table_list";
/*******************/
echo "</td><td valign=top>";
//interogare
$select = "SELECT * FROM ".$tabela." ";
$query = odbc_exec($odbc, $select ) or die (odbc_errormsg());
// afisare tabela
echo "<center>Tabela <b>".$tabela." </b></center><br>";
echo "<table border=1 width=90% align=center style='border-collapse:collapse' cellpadding=1 cellspacing=0>";
// afisare cap tabel cu numele campurilor
$i = 0;
$fieldCount = odbc_num_fields($query);
echo " <tr bgcolor=#d0d0ee>\n";
while ($i < $fieldCount)
{
$i++; // star de la 1
$fieldName = odbc_field_name($query, $i);
$colorat=(trim($fieldName)=="name")?'#ddccaa':'#d0d0ee'; //colorez fieldul 'name' daca exista intr-una din tabele
echo "<td bgcolor=".$colorat.">".$fieldName."</td>\n";
}
echo "</tr>\n";
// afisare intregistrari
while($row = odbc_fetch_array($query)){ // functie din odbc.php daca nu exista in php
echo '<tr valign=top bgcolor='.(($col++ % 2)?'#f0f0f0':'#e0e0e0').'>';
foreach ($row as $key => $value) {
echo '<td align=center>'.$value.'</td>';
}
echo '</tr>';
}
echo '</table>';
echo "</td></tr>";
echo "</table>";
odbc_close($odbc);
?>
m-am chinuit putin da' pan' la urma am reusit, problema mea era cu configurarea conexiunii odbc din control panel
sper sa ajute si pe altii :)
interesant ar fi conexiunea fara odbc, sa nu trebuiasca sa configurezi din control panel conexiunea
ceva cu COM :?: :roll: |
|
| Sus |
|
PHPRomania Bot
Bot Member
Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google |
| Trimis: Mie Dec 26, 2007 7:01 pm Titlul subiectului: Ad |
|
|
|
|
|
| Sus |
|
| |
|