/    Sign up×
Community /Pin to ProfileBookmark

Selecting table names from sql databse using php oops

hello
Please look at the code
Why is this returning a record which does not exists in the database and also it returns 62 arrays

[code]
public function DomainSearch($domain)
{
$array = array();
$query = “SELECT ‘”.$domain.”‘ FROM INFORMATION_SCHEMA.TABLES”;
$result = mysqli_query($this->conn, $query);
while ($row = mysqli_fetch_assoc($result)) {
$array[] = $row;
}
echo “<pre>”;
print_r($array);
echo “<pre>”;
// $result = mysqli_num_rows($result);

}
}

$domain = “example_com”;

$test = new DatabaseConnection();
$test->DomainSearch($domain);
[/code]

the result

[code]

Array
(
[0] => Array
(
[example_com] => example_com
)

[1] => Array
(
[example_com] => example_com
)

[2] => Array
(
[example_com] => example_com
)

[3] => Array
(
[example_com] => example_com
)

[4] => Array
(
[example_com] => example_com
)

[5] => Array
(
[example_com] => example_com
)

[6] => Array
(
[example_com] => example_com
)

[7] => Array
(
[example_com] => example_com
)

[8] => Array
(
[example_com] => example_com
)

[9] => Array
(
[example_com] => example_com
)

[10] => Array
(
[example_com] => example_com
)

[11] => Array
(
[example_com] => example_com
)

[12] => Array
(
[example_com] => example_com
)

[13] => Array
(
[example_com] => example_com
)

[14] => Array
(
[example_com] => example_com
)

[15] => Array
(
[example_com] => example_com
)

[16] => Array
(
[example_com] => example_com
)

[17] => Array
(
[example_com] => example_com
)

[18] => Array
(
[example_com] => example_com
)

[19] => Array
(
[example_com] => example_com
)

[20] => Array
(
[example_com] => example_com
)

[21] => Array
(
[example_com] => example_com
)

[22] => Array
(
[example_com] => example_com
)

[23] => Array
(
[example_com] => example_com
)

[24] => Array
(
[example_com] => example_com
)

[25] => Array
(
[example_com] => example_com
)

[26] => Array
(
[example_com] => example_com
)

[27] => Array
(
[example_com] => example_com
)

[28] => Array
(
[example_com] => example_com
)

[29] => Array
(
[example_com] => example_com
)

[30] => Array
(
[example_com] => example_com
)

[31] => Array
(
[example_com] => example_com
)

[32] => Array
(
[example_com] => example_com
)

[33] => Array
(
[example_com] => example_com
)

[34] => Array
(
[example_com] => example_com
)

[35] => Array
(
[example_com] => example_com
)

[36] => Array
(
[example_com] => example_com
)

[37] => Array
(
[example_com] => example_com
)

[38] => Array
(
[example_com] => example_com
)

[39] => Array
(
[example_com] => example_com
)

[40] => Array
(
[example_com] => example_com
)

[41] => Array
(
[example_com] => example_com
)

[42] => Array
(
[example_com] => example_com
)

[43] => Array
(
[example_com] => example_com
)

[44] => Array
(
[example_com] => example_com
)

[45] => Array
(
[example_com] => example_com
)

[46] => Array
(
[example_com] => example_com
)

[47] => Array
(
[example_com] => example_com
)

[48] => Array
(
[example_com] => example_com
)

[49] => Array
(
[example_com] => example_com
)

[50] => Array
(
[example_com] => example_com
)

[51] => Array
(
[example_com] => example_com
)

[52] => Array
(
[example_com] => example_com
)

[53] => Array
(
[example_com] => example_com
)

[54] => Array
(
[example_com] => example_com
)

[55] => Array
(
[example_com] => example_com
)

[56] => Array
(
[example_com] => example_com
)

[57] => Array
(
[example_com] => example_com
)

[58] => Array
(
[example_com] => example_com
)

[59] => Array
(
[example_com] => example_com
)

[60] => Array
(
[example_com] => example_com
)

[61] => Array
(
[example_com] => example_com
)

[62] => Array
(
[example_com] => example_com
)

)

[/code]

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 16.2022 — Do you know anything about using mysql? From your question I definitely think that the last thing you s/b querying is the information schema!

And it actually returned 63 arrays. Which one of those identical rows is 'not in the database'?

And that form of a query will return whatever you type in there.

And it is silly to do a query and then loop thru it and save each result record into an array. You pretty much already had an array of records, so now you have 2 of them. Why?
Copy linkTweet thisAlerts:
@slake8authorAug 16.2022 — I solved it like this
<i>
</i>$array = array();
$query = "SELECT * FROM information_schema.tables
WHERE table_name = '".$domain."'";
<br/>
<i> </i>
Copy linkTweet thisAlerts:
@ginerjmAug 16.2022 — Doesn't look solved...

$query = "SELECT * FROM information_schema.tables<br/>
WHERE table_name = '$domain'";


This works as well. Although I have to wonder why you label an argument that is clear related to a table name as 'domain'
Copy linkTweet thisAlerts:
@NogDogAug 16.2022 — > @slake8#1645977 I solved it like this

While that solves that particular query, there's a database design "smell" here, if you are creating a new table for each new "domain". _Maybe_ there's a good reason, but my instinct is that a single domain table with typical relational database joins to other related tables would make more sense?
Copy linkTweet thisAlerts:
@ginerjmAug 16.2022 — And just what kind of developer EVER reads the SCHEMA database? Not something I have ever had to use and here's the OP who doesn't even know how to write queries using it for some purpose.
Copy linkTweet thisAlerts:
@yourtechmastersAug 16.2022 — @slake8#1645977

The short form is [perfect ](https://yourtechmaster.com/)since we use it.
Copy linkTweet thisAlerts:
@ginerjmAug 16.2022 — The 'short form'?? In what regard are you using that term?
Copy linkTweet thisAlerts:
@NogDogAug 17.2022 — @ginerjm#1645993 It was a spammer trying to sneak in a link...they've been banned.
Copy linkTweet thisAlerts:
@ginerjmAug 17.2022 — And we seemed to have lost our OP. It's been quite some time for someone who must be curious about what he may be doing wrong.
Copy linkTweet thisAlerts:
@slake8authorAug 20.2022 — Hello,

It seems like I need a proper training

😀😀😀😀

I just want to create an app that should visit a website with curl and saves the date of the search execution and response time from the curl header in a database, later I wanted to display the latest 10 searches from the database

Can you guys guide me with the database structure?
Copy linkTweet thisAlerts:
@sibertAug 20.2022 — Once you collected the data, here is a rough attempt to store and retrieve.

https://www.db-fiddle.com/f/eaQG8H4yqY9hnQBZjzJgz/109

Just click RUN to execute the query.
Copy linkTweet thisAlerts:
@slake8authorAug 20.2022 — Thank you for the solution

So I will store all the data in one table " Domains "

Copy linkTweet thisAlerts:
@slake8authorAug 20.2022 — Will It not get slow If the table goes too long
Copy linkTweet thisAlerts:
@sibertAug 20.2022 — > @slake8#1646111 Will It not get slow If the table goes too long

Nope. Maybe some extensive search will be slower when reaching some millions of records. But using LIMIT 10 I am sure that millions of records will not affect the speed.
Copy linkTweet thisAlerts:
@sibertAug 20.2022 — > @slake8#1646110 So I will store all the data in one table " Domains "

Yes. But note that using **domains** will be better than **Domains**
Copy linkTweet thisAlerts:
@slake8authorAug 20.2022 — Thank you really appreciated
×

Success!

Help @slake8 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 7.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @Nanditha,
tipped: article
amount: 1000 SATS,
)...